BCrypt哈希错误

这是我的散列密码的代码,并将已有的密码与已经发送到正文请求的密码进行比较: //hash password of document that use this schema bcrypt.hash(user.password, null, null, function (err, hashed) { if (err) { throw err; } else { user.password = hashed; //next api next(); } }) }); userSchema.methods.comparePassword = function (password) { //refer at userSchema var user = this; //return method of bcryot library that compare two string: original […]

在节点中不可能安装包

我想安装一个树莓派3.我想安装和运行节点代码,但是在使用npm安装软件包时遇到问题。 我尝试了几个版本的节点(包括armhf最新和更旧的版本),但我总是得到以下错误(在安装槽[npm安装槽] groove@2.5.1 install /home/pi/node_modules/groove node-gyp rebuild make: Entering directory '/home/pi/node_modules/groove/build' CXX(target) Release/obj.target/groove/src/groove.o In file included from ../src/groove.cc:4:0: ../src/file.h:6:27: fatal error: groove/groove.h: Aucun fichier ou dossier de ce type #include <groove/groove.h> ^ compilation terminated. groove.target.mk:95: recipe for target 'Release/obj.target/groove/src/groove.o' failed make: *** [Release/obj.target/groove/src/groove.o] Error 1 make: Leaving directory '/home/pi/node_modules/groove/build' gyp ERR! build error gyp ERR! […]

Jesttesting简单的香草JavaScript – 不能读取null的属性'addEventListener'

我试图用Jest和Node.js来testing我的应用程序。 使用JestJS运行testing时,避免在terminal中出现以下错误的正确设置是什么? 无法读取null的属性“addEventListener” sum函数的testing通过我注释掉在app.js文件中添加事件监听器。 我甚至不知道为什么这行以及由Jest执行的console.log('Not part…') ,因为我只导出sum函数。 我的index.html文件的内容: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <button id="button">JavaScript</button> <script src="./app.js"></script> </body> </html> 我的app.js文件的内容: function sum(a, b) { return a + b; } console.log('Not part of module.exports but still appearing in terminal, why?'); var button = document.getElementById('button'); button.addEventListener('click', function(e) { console.log('button was clicked'); }); module.exports […]

使用dynamic名称和dynamic嵌套级别访问对象属性

我从string中读取要访问的对象的属性:level1.level2.property或level1.property OR …名称和嵌套可能会有所不同。 我将这些对象存储在一个单独的模块(workerFunctions)中。 我知道我可以用[]符号dynamic地访问对象,例如: var level1="level1"; var property="property"; console.log(workerFunctions[level1][property]) 但是,我不知道如何从不同的inputstringdynamic地构造这个“workerFunctions [level1] [property]”,所以产生例如: console.log(workerFunctions[level1][level2][property]) 由于string:level1.level2.property。 先谢谢你。

禁用关键错误的快速error handling

app.use(function (req, res, next) { throw new Error('critical'); }) 使快速服务器捕捉到一个严重的错误,并输出它,而我希望它崩溃。 添加error handling程序不会replace默认处理程序。 对于严重错误,如何禁用快速error handling?

如何运行promise数组

在这个函数中,在内联数组完成之前调用callback函数。 我只能在内联具有所有的值时才能调用它? function inlineSearch( search, callback ) { const inline = [] mal.quickSearch( search ).then( response => { response.anime.forEach( anime => { anime.fetch( ).then( json => { inline.push( replyInline( json ) ) }) }) .then( callback( inline ) ) } ) } response.anime是一个json对象数组,指向另一个json对象,这就是为什么我需要获取它,所以我可以有正确的json。 而且, replyInline是一个只接受json并返回另一个的函数。 mal =我的动漫列表API

如何确保所有玩家在socket.io问答游戏中同时显示问题?

我正在开发一个在客户端浏览器中运行的多人测验游戏。 它在服务器端使用socket.io和node.js,在客户端使用javascript。 从数据库中挑选问题并同时发送给每个玩家,但是较慢的互联网连接可能意味着他们将在不同的时间接收这些问题。 可能的scheme 发送每个问题的时间戳,告诉浏览器何时显示问题。 时间戳将是(发送时间+ x秒)来解决连接延迟。 但是,如果客户知道如何使用控制台,他们可以在问题到达时立即拦截问题,并在所有其他玩家之前看到。 那么我怎么能确保没有一个玩家有不公平的优势?

错误:configuration文件丢失 – /nodeapp/node_modules/aws-sdk/lib/request.js:31

我从AWS-SDK中使用s3.listObjects()函数拉对象,并且不断收到以下错误: /nodeapp/node_modules/aws-sdk/lib/request.js:31 其次是 Error: Missing credentials in config at IncomingMessage.<anonymous> (/nodeapp/node_modules/aws-sdk/lib/util.js:863:34) at emitNone (events.js:91:20) at IncomingMessage.emit (events.js:186:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:74:11) at process._tickDomainCallback (internal/process/next_tick.js:122:9) 这不加起来,因为我有一个不同的路线(downloadParam),从S3中检索一个对象,而不会给我这个错误。 此外,当我注销从downloadResults路由检索到的对象,似乎检索对象没有问题,但我仍然会得到这个错误。 我花了几个小时在这个问题上,我似乎无法弄清楚为什么会发生这种情况。 我已经粘贴了两条路线的代码,一个是有效的,另一个是没有的。 从我在线收集的信息来看,这看起来更像是一个代码问题,而不是AWS-SDK的凭证问题。 downloadParam: function(app, s3){ app.use('/api', apiRoutes) apiRoutes.get('/download-param-file', function(req, res, next){ res.set({'Content-Type':'text/csv'}) s3.getObject({Bucket: 'some-bucket', Key: 'some-key' + req.query.fileName}, function(err, file){ if (err) { console.log(err); return next(err); […]

在terminal中运行js文件

我试图在一个空的文件夹中运行这个简单的文件 // time.js const moment = require('moment') function getDay() { var today = moment().day() console.log(today); } getDay() 使用node time.js 但是我明白了 Error: Cannot find module 'moment' 但是我已经运行npm install -g moment和npm install moment 。 我在做什么noob错误?

数组在Nodejs和MongoDB中用forEach循环返回null值

我使用Nodejs,MongoDB和Express编码。 下面的代码在MongoDB中查找具有特定ID的用户对象。 一旦find用户对象,它将检索该对象的collections属性。 favorite属性是一个数组,其每个元素都是一个产品的_id。 我试图循环这个数组。 每个循环,我尝试从MongoDB中检索一个产品对象,并将这个产品对象附加到新的数组(在我的代码下面,它被称为“列表”)。 我把一些console.log()来检查列表的值。 它对每个循环都有价值,但是最后当我得到最后一个时,它是空的。 我知道问题发生,因为我没有正确使用deferred.resolve和deferred.promise。 请帮我解释deferred.resolve和deferred.promise在代码中的作品。 非常感谢你 function showBasket(user) { var deferred = Q.defer(); var list =[]; db.users.findById(user, function (err, user) { if (err) deferred.reject(err); if (user) { var favorite = user.favorite; favorite.forEach(function(e){ db.products.findById(mongo.helper.toObjectID(e), function(err, product){ if (err) deferred.reject(err); if (product) { list.push(product); console.log(list);// list has value here } })//end db.products.findById […]