Tag: javascript

如果投票阶段被devise为等待callback被添加,那么节点如何知道什么时候退出?

从nodejs文档中取一行: 如果脚本没有被setImmediate()调度,事件循环将等待callback被添加到队列,然后立即执行。 我的问题是,如何nodejs知道什么时候退出id事件循环的目的是等待事件,如果没有。 例如: console.log("Hello World"); 以上只是退出。 没有预定的事件,但根据文档节点应该等待。

如何使用mongoose羽毛适配器编写一个聚合体?

我是feathersjs框架的新手,并试图写聚合查询它不能正常工作。 hook.app.query = { lookup: { from: "orders", localField:"serviceLocationId", foreignField:"serviceLocationId", as: "orders" }, match: { serviceLocationId : { $in: Array.from(new Set(reqArr)) } }, limit: 14 } hook.app.service('servicelocations') .find(hook.app.query) .then(result => { console.log(result) })

困在节点js的回拨地狱

我试图修改这个节点库来添加一个额外的存在方法 这是链接到图书馆 – https://github.com/mikolalysenko/interval-tree-1d/blob/master/interval-tree.js 这是我创造的 proto.queryPointExists = function(x, cb) { if(x < this.mid) { if(this.left) { var r = this.left.queryPointExists(x, cb) if(r) { return r } } return reportLeftRangeExists(this.leftPoints, x, cb) } else if(x > this.mid) { if(this.right) { var r = this.right.queryPointExists(x, cb) if(r) { return r } } //console.log(reportRightRangeExists(this.rightPoints, x, cb)); return reportRightRangeExists(this.rightPoints, […]

如何编写graphql的中间件,这将在每个parsing器之前调用

在每一个请求我发送令牌,并检查它在快递中间件 app.use(async (req, res, next) => { const authorization = req.headers.authorization; let token = null; let user; if (authorization) { try { token = jwt.verify(authorization, config.secret); } catch (e) { // dont work throw new GraphQLError({ message: 'token damaged' }); } if (token) { const { _id } = token; user = await User.findOne({ _id […]

使用Node.js和MySQL查询函数callback来确定范围

我正在尝试使用Node和MySQL编写JavaScript对象作为购物任务的一部分。 我想通过使它比function性编程更多的OOP来testing自己。 我正在创build一个交易对象的构造函数,其中包含所选项目的属性,数量和总成本。 此外,将是显示项目,select项目和购买项目的方法。 开始时,我想也有一个唯一的itemID数组,这将是用户select一个有效的产品的validation。 我有一个范围问题,如果在对象的作用域中定义this.ids []是未定义的。 我的解决scheme将在本地定义它,并将该数组作为parameter passing,以避免范围界定。 这个解决scheme也不会允许我访问Transaction对象的作用域variables。 this.listProducts = function(connection) { connection.query("SELECT * FROM products WHERE stock_quantity>0", function(err,res) { if (err) throw err; this.ids = []; for (var i = 0; i < res.length; i++) { this.ids.push(res[i].item_id); console.log(res[i].item_id + " " + res[i].product_name + " " + res[i].price); } // res.forEach(function (element) […]

在创build模型时产生连接错误

当我执行这个程序时,一切工作正常: const Sequelize = require("sequelize"); const Conn = new Sequelize("data","postgresql","postgresql", { 'host' : "localhost", 'dialect' : "postgres", 'port' : "1337" }) // piece of code to be added here Conn.sync().then(function(){ console.log('DB connection sucessful.'); }, function(err){ console.log(err); }); 控制台日志: DB connection successful. 当我添加这条线: const User = Conn.define('user', { firstName: { type: Sequelize.STRING }, lastName: { type: […]

alasql:保存对象中的所有数据时,应用程序性能不受影响?

我正在开发一个电子应用程序 我有一个有35个字段的表格,用户将在每个表格中logging5000到40000个logging。 我用alasql的FILESTORAGE做了一些存储testing,并将数据库文件的对象保存在一个对象中 我的问题是,它会不会影响我的应用程序在一个对象中拥有如此多的持久数据的性能? 如果是这样,你build议我做什么? 非常感谢。

在打字稿中访问Nodejsstream的highWaterMark属性给出:“Property'_readableState'不存在”错误

我的问题是关于nodejs中的打字稿和stream。 我不想扩展stream基类,并访问highWaterMark选项。 在打字稿中,以下代码起作用(即打印highWaterMark选项) import * as stream from 'stream'; class ExampleStream extends stream.Readable { constructor() { super(options) console.log(this._readableState.highWaterMark) } _read() {} _write() {} } 但打字稿给我关于这一行的以下错误信息: console.log(this._readableState.highWaterMark) ['ts]types'ExampleStream'上不存在'_readableState'属性。 我如何解决这个问题?

“永远”的node.js安装,但不再工作

一两天前,我用npm安装了“ forever ”包,并且永远CLI按预期工作。 然而,今天当我试图永远使用(使用命令forever start app.js ),它给了以下错误消息(格式化我的): forever : The term 'forever' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 我已经尝试过永久重新安装,npm / node.js和Visual Studio Code(我当前的IDE /文本编辑器),但是这些都不起作用。 也没有重新启动我的电脑。 […]

找不到mongoose模式

我尝试创build一个专用的mongoosecreateConnection。 Node.js融合: MyModel = conn.model('Profile',profileSchema), profileSchema未定义。 但是我哪里错了? //my db.js const mongoose = require('mongoose'); const conn = mongoose.createConnection = ("mongodb://localhost:27017/myDatabase"), MyModel = conn.model('Profile', profileSchema), m = new MyModel; m.save(); //works; if (process.env.NODE_ENV === 'production') { conn = process.env.MONGODB_URI; } require('./profiles) 这里是我的模型页面的其余部分: // my profile.js // JavaScript source code const mongoose = require('mongoose'); const profileSchema = new […]