我在基于 Nest.js 的项目中导入 ESM 模块时遇到问题。据我了解,这个问题不仅与 Nest.js 有关,也与 Typescript 相关。
我尝试了 Node.js 和 typescript 版本的各种操作和组合,添加"type":"module"到文件package.json的设置并进行更改,因此它具有以下视图,与默认值tsconfig.json相去甚远:
{
"compilerOptions": {
"lib": ["ES2020"],
"esModuleInterop": true,
"module": "NodeNext",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "Node",
"target": "esnext",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
}
}
Run Code Online (Sandbox Code Playgroud)
我的完整环境是:
我知道Nest.js是在 Express JS 之上并且可以在 fastify 上,我已经在 Mozilla (MDN) 培训网站上完成了 Express JS 库项目,但由于很多原因,例如应用程序的架构以及我在网上看到的有关问题情况的讨论使用快速和现代的 JS,如 async-await 等\xe2\x80\xa6
我寻找了一个更可靠的选择: sails-js、nest 和feather 出现了,feathers 非常棒,但是Nest.js有非常好的文档,我有一段时间避免使用 typescript,但现在它似乎无处不在,我希望通过 Nest 我可以更好地了解它以及它的实际用途,在前端,除了 Angular 2 plus 之外,我真的找不到使用它的好理由,除了它是一种趋势。不要误会我的意思,角度是我希望加入 TS 的原因之一。
这就是我作为前端开发人员(主要是 vue 和 svelte)在 NodeJS 氛围(express 和 hapi)中几个月的现状,我的问题是:我应该坚持 hapi 和express 还是使用 NestJs 和替代品(如 Feathers 和 sails)?
\n请原谅我缺乏英语写作经验。
\n由于zlib已经添加到node.js中,我想问一个关于使用样式解压缩的问题.gz,async/await不使用using streams,一一解压。
在下面的代码中,我使用的fs-extra是而不是标准fs&打字稿(而不是js),但至于答案,它是否具有js或ts代码并不重要。
import fs from 'fs-extra';
import path from "path";
import zlib from 'zlib';
(async () => {
try {
//folder which is full of .gz files.
const dir = path.join(__dirname, '..', '..', 'folder');
const files: string[] = await fs.readdir(dir);
for (const file of files) {
//read file one by one
const
file_content = fs.createReadStream(`${dir}/${file}`),
write_stream = fs.createWriteStream(`${dir}/${file.slice(0, -3)}`,),
unzip = zlib.createGunzip();
file_content.pipe(unzip).pipe(write_stream);
} …Run Code Online (Sandbox Code Playgroud) 我有一个文档(在聚合内部,在$group阶段之后),其中有一个带有值的对象(但如果需要的话,我可以形成数组)number。
MongoPlayground 示例,其中包含数据和我的聚合查询。
我想_id在下一$project阶段创建一个新字段,由这三个number值组成,例如:
item_id | unix time | pointer
_id: 453435-41464556645@1829
Run Code Online (Sandbox Code Playgroud)
问题是,当我尝试使用 时$concat,查询返回一个错误,例如:
$concat only supports strings, not int
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:有可能取得这样的结果吗?我已经看到相关问题MongoDB concatenate strings from Two fields into a Third field,但它没有涵盖我的情况。
Next.js我是新 @frontend,发现创建一个简单的搜索表单并使用Formik从我自己的 API 获取的数据并将其返回到页面上有点困难。由于相关信息不多,或者有,但没有涵盖整个过程,所以我决定创建这个问题。
我在处理什么:
建筑学:
前端发送请求(基于表单输入) - >服务器接收它(使用它进行操作)并用json对象响应 - >前端接受它,并将结果显示回页面上。
一个简单的 Node.js Express 服务器,具有单路由 (localhost:port/users/:id),当您请求它时,./users/100它会json以 {id}+1 增量返回,例如{id:101}下面的示例代码:
var express = require('express');
var router = express.Router();
/* CORS ARE FINE */
router.get('/:id', function(req, res) {
res.json({id: parseInt(req.params.id)+1});
});
module.exports = router;
Run Code Online (Sandbox Code Playgroud)
我已经编写了MyForm组件并将其插入到我的主页上。这是组件的代码MyForm:
import React from 'react';
import fetch …Run Code Online (Sandbox Code Playgroud) 我正在尝试安装 rn-push-notifications,我需要 google play services 版本和 firebase 版本。你能帮我一下吗?
javascript react-native react-native-push-notification react-notifications
{
"customerSchemes": [
{
"name": "A",
"startDate": some date in valid date format
},
{
"name": "B",
"startDate": some date in valid date format.
}
]
}
Run Code Online (Sandbox Code Playgroud)
我试图找出方案 A 在方案 B 之前开始的所有文档。请注意,方案数组不是按 startDate 的升序排列的。与计划 A 相比,计划 B 可以有一个更早的日期。我相信 unwind operator 在这里可能会有一些用处,但不确定如何进行下一步。
我有以下实体:
@Entity({ name: 'user' })
export class UserEntity extends BasicEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({
nullable: false,
unique: true,
})
login: string;
}
Run Code Online (Sandbox Code Playgroud)
@Entity({ name: 'wallet' })
export class WalletEntity extends BasicEntity {
@PrimaryGeneratedColumn()
id: number;
@ManyToOne(() => UserEntity)
@JoinColumn({ name: 'user_id' })
user: UserEntity;
@Column({
name: 'address',
type: 'text',
})
address: string;
}
Run Code Online (Sandbox Code Playgroud)
所以,钱包表看起来像这样:
-------------------------
id | user_id | address
-------------------------
1 | 1 | 0x12
-------------------------
2 | 43 | 0x10
Run Code Online (Sandbox Code Playgroud)
我喜欢通过 Repository api 更新wallet实体。但问题是,我不能只是:
WalletRepository.save({ …Run Code Online (Sandbox Code Playgroud) 我的 MongoDB (v.4.4) 中有以下集合:
guilds:
{
_id: String,
members: [{ _id String, rank: number },{ _id String, rank: number }...]
}
Run Code Online (Sandbox Code Playgroud)
和characters:
{
_id: String,
many_other: 'fields'
}
Run Code Online (Sandbox Code Playgroud)
我想按字段加入管道$lookup语法。guild.members <= characters_id
我不使用 Mongo 内置
OjbectIdsas_id,我用两个集合中的字符串覆盖它。$lookup据我所知,字符串的行为与管道中的行为有些不同_id。因此,在回答之前,请确保您知道这一点。
我想要的预期结果很简单,我想保存原始文档的排名,并从中添加任何其他字段$lookup:
{
_id: String // (guild)
members: [
{
_id: String, // (characters)
rank: number,
many_other: '...fields from characters'
},
{
_id: String, // (characters)
rank: number,
many_other: '...fields …Run Code Online (Sandbox Code Playgroud) 我遇到了一个问题,我尝试解决了很长时间。我正在尝试从nodejsvia连接到 Mongo Atlas 云mongoose。这不是我第一次,但我就是找不到答案。
猫鼬版本:5.9.22
这是我的代码:
const express = require('express')
const mongoose = require('mongoose')
const bodyparser = require('body-parser')
const app = express()
app.use(bodyparser.json())
mongoose.connect("mongodb+srv://dudvil1:password@cluster0.guxmm.mongodb.net/shopping_list?
retryWrites=true&w=majority", {
useNewUrlParser: true,
useUnifiedTopology: true
})
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => console.log('mongo connected'))
.catch(err => console.log(err));
const port = process.env.PORT || 5000
app.listen(port, () => console.log(`server started in port ${port}`))
Run Code Online (Sandbox Code Playgroud)
我的白名单设置只包括 0.0.0.0/0 我在数据库访问中的用户名和密码很简单,没有任何特殊字符,但总是得到同样的错误:
MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is …Run Code Online (Sandbox Code Playgroud) javascript ×5
node.js ×5
mongodb ×4
mongoose ×3
nestjs ×3
typescript ×3
es6-modules ×1
express ×1
formik ×1
next.js ×1
postgresql ×1
react-native ×1
react-native-push-notification ×1
reactjs ×1
sails.js ×1
typeorm ×1
zlib ×1