网站搜索
所以我正在学习 NodeJS 和 JavaScript 一般知识,并且在玩它时,我在解析 JSON 时遇到了一些问题。我从“用户”那里收到以下内容:
{ "sync_contact_list": [ { "name": "c", "number": "789", "email": "" }, { "name": "b", "number": "123", "email": "[email protected]" }, { "name": "a", "number": "416", "email": "" } ] } 阅读更多 →
嗨,现在我知道 NodeJS 是异步的(说实话,我仍在努力理解这一点)。
我目前面临的问题是我正在尝试做一个 http.request 来接收一些 JSON 数据。这没问题,但我需要的是将这些数据返回到一个变量。我相信我需要做一个回调函数?(根据我阅读过的相关资料)
我目前拥有的代码:
var http = require('http'); pCLatLng = ''; function postCodeCheck() { var pCode = { host: 'geo.jamiethompson.co.uk', path: "/" + 'SW1A2AA' 阅读更多 →在 NodeJS 生产环境中使用 TypeScript 编译器选项 --inlineSourceMap 会有显著的性能损失吗?
我不建议在生产环境中这样做。关于 sourceMaps,StackOverflow 上已经有相关讨论。不过在你的 Node.js 应用中启用它会使 js 文件大小翻倍,我个人认为那并不是很好 🤞
阅读更多 →我正在尝试在 NodeJS 中使用 typescript-collections 的 Dictionary 类:
/// <reference path="../../../scripts/collections.ts" /> var collections = require('../../../scripts/collections'); export class AsyncProcessorCommand implements interfaces.IAsyncProcessorCommand { public static Type = 'RabbitMon.AsyncProcessorCommand:RabbitMon'; public GetType = () => 'RabbitMon.AsyncProcessorCommand:RabbitMon'; public ID: string; constructor(public Action: string, public Argum 阅读更多 →我正在使用 TypeScript 构建一个 Node.js 项目。在这个项目中,我想添加一些文件/目录命名规则。例如,文件/目录名称应该使用下划线命名(sneak-case)。
有没有办法像我们用 tslint 给编码规范规则一样,对文件名施加任何限制?
阅读更多 →我有一个代码块,其中有两个 await 语句。我认为第一次服务器运行时,它会直接跳过 await SQL.connect。在经过几次调用(允许连接时间)之后,这个过程就能正常工作了。
这是针对 NodeJS 的 MSSQL 包的。
为什么我的第一个 await 不会等待?
async execStoredProc(spDescriptor: StoredProcedureDescriptor) { if (!this.pool) { if (this.isFirst) { this.isFirst = false ; } else { SQL.close(); } this.pool = await SQL.connect(this.config); } try { const request = new SQL.Request(this.pool) ; 阅读更多 →
构建一个默认的 react-native 应用,使用 Typescript 并添加 styled-components,在应用中引用它并尝试编译时会导致以下错误:
node_modules/styled-components/typings/styled-components.d.ts(116,44): 错误 TS2503: 找不到命名空间 'NodeJS'。
请查看仓库以重现。https://github.com/StevenTCramer/Issue1
阅读更多 →关于 webpack 关于外部库和 nodejs 的文档,有信息指出应该能够导入 node 模块。除非我想导入 http2,否则工作得非常完美。它打印出以下错误:
ERROR in ./src/index.ts Module not found: Error: Can't resolve 'http2' in 'absolutepath/to/src'入口 TypeScript 文件简化后如下所示:
import { readFileSync } from 'fs'; import { createSecureServer } from 'http2'; const server = createSecureServer({...});而 webpack 配置文件如下所示:
const path = require('path'); module.exports = { entry: '. 阅读更多 →你好,我正在编写一个简单的网页应用程序,使用类似于外观设计模式的设计。该应用程序使用 Typescript 编写,使用 nodejs、expressjs、node-postres 和 inversify。假设我有这个简单的例子
路由器.ts
router.get('/test', testController.test);TestController.ts
import { Request, Response } from 'express'; import { ITestUC } from '../usecase/TestUC'; import { di } from '../core/Di'; import { TYPES } from '../core/Types'; class TestController { public async test(req: Request, res: Resp 阅读更多 →
我能够使用 multer 成功地将图像存储在本地磁盘存储中,但在使用 GET 方法时,会抛出“Cannot GET /uploads/image-1547436792386”错误。我在下面提供了我的 image-upload.js 代码:
const multer = require('multer'); const storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, 'uploads/'); }, filen 阅读更多 →