温斯顿 – 如何logging导致节点进程崩溃的错误?

我有一个快速的应用程序,有一些情况下,整个节点进程将失败,主要是ReferenceError。 我想知道是否有一种方法来设置Winston来处理节点崩溃,并logging显示在我的控制台中的问题。 例如,我可以强制我的应用程序崩溃,通过放入一个对window的引用,导致: ReferenceError: window is not defined 我怎样才能让winstonlogin呢? 在我的app.js中,我为Winston设置了以下设置,但不起作用: const winston = require('winston'); const logger = new (winston.Logger)({ transports: [ new (winston.transports.File)({ filename: `results.log`, timestamp: true, level: 'info', json: true, eol: 'n', handleExceptions: true, humanReadableUnhandledException: true }) ], exitOnError: false }); process.on('uncaughtException', function (error) { console.log('error'); // doesn't log this, }); 有人可以帮我吗? 基本上,我正在尝试logging我的控制台中出现的这个错误,如果我故意让应用程序崩溃: Listening […]

如何将Mongoose / MongoDB包含在Express.JS应用程序中(ES2015方式)

我试图在我的Express.JS应用程序(ES2015方式)中包含mongoose/ mongodb。 首先,我有主文件: import path from 'path' import express from 'express' import mongoose from 'mongoose' mongoose.connect('mongodb://localhost/timelines') const app = express() app.use(express.static('dist/client/')) app.get('*', (req, res) => { res.sendFile(path.resolve('dist/client/index.html')) }) app.listen(3000) 然后错误信息: [nodemon] starting `node dist/server/app.js` undefined:8 driver = !(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND';; throw e; }()); ^ […]

在deepEqual中奇怪的新date

我有这个代码 var assert = require('assert'); describe('date', function() { it('deep equal', function() { assert.deepEqual({date: ''}, {date:new Date()}); }); }); 当我用摩卡进行testing时,我得到了这个 AssertionError: { date: '' } deepEqual { date: 2017-03-08T21:58:45.767Z } + expected – actual { – "date": "" + "date": [Date: 2017-03-08T21:58:45.767Z] } at Context.<anonymous> (test/test_date.js:5:12) 为什么deepEqual生成的date格式为[Date: 2017-03-08T21:58:45.767Z]而不是这种格式2017-03-08T21:58:45.767Z ? 为什么生成的date在括号[Date: …] ?

string模式到正则expression式

我正在使用mongodb来存储数据。 我想存储完整的正则expression式作为string: { permissions: [{ resName: '/user[1-5]/ig', isRegex: true }] } 我知道有模块mongoose-regexp可以存储RegExp,但我想存储正则expression式和string在同一个字段。 我已经实现了使用eval(user.permissions[i].resName).test(resName) 。 我想知道这是否是正确的方法,如果有任何替代(即使用new RegExp(…) ) 编辑 我试图避免eval因为这个字段是来自用户input,如果有什么东西发送到数据库可能是一个问题。

有Mongoose限制子文档的MongoDB

谈到MongoDB和Mongoose,我是一个noob,所以请原谅我… 我正在使用Express和Mongoose一起使用Node。 我有一个大量的子文档的文档,以至于当我试图加载所有的子文档时,我的服务器耗尽内存。 所以我想select一个子文档的最后30个项目。 这是我现在所拥有的,然后猜测我想要的是什么… Device.findOne({ device_id: deviceId }, (err, device) => { …. }) 这是一个猜测 Device.findOne({ device_id: deviceId }, { movements: { $slice: 30 } }, (err, device) => { …. }) 任何帮助将是可怕的,在此先感谢!

编译错误:找不到模块'util'

我是angular2上的新程序员。 我有问题时,与angularcli编译。 我通过angular度cli生成angular度2项目。 我试图通过导入模块像这样在node_modules/@types/node上使用debuglog模块: import {debuglog} from "util"; 我使用Webstorm IDE进行开发,IDE不会警告或错误导入。 我检查并findpath中的debuglog模块: myproject/node_modules/@types/node/index.d.ts 。 我的代码有什么问题? 有任何build议修复它? Github上的项目: https : //github.com/sinhpn92/angular2-example-types-node 环境版本: @angular/cli: 1.0.0-rc.1 node: 7.7.1 os: darwin x64 @angular/common: 2.4.9 @angular/compiler: 2.4.9 @angular/core: 2.4.9 @angular/forms: 2.4.9 @angular/http: 2.4.9 @angular/platform-browser: 2.4.9 @angular/platform-browser-dynamic: 2.4.9 @angular/router: 3.4.9 @angular/upgrade: 2.2.4 @angular/cli: 1.0.0-rc.1 @angular/compiler-cli: 2.4.9

根据数据库结果确定dynamic路由

我正在尝试为我的应用程序创build特定的路由规则。 不过,我希望这些规则是基于数据库中表格内容的通用方法。 这意味着根据数据库规则,有时可能会在restify服务中插入或删除一些路由。 我正在寻找一个解决scheme,但我找不到任何东西,这里是我的代码的一个例子: server.put('/logging/create', function(req, res, next){ return next(); }); server.delete('/logging/delete', function(req, res, next){ return next(); }); server.post('/logging/update', function(req, res, next){ return next(); }); 我想实现的是在不重新启动节点js脚本的情况下即时添加/删除特定的请求。 我所拥有的是一个包含所有规则的数组。 一个规则的例子是: { "name":"/logging/create", "method":"put", "status":"active" }, { "name":"/logging/delete", "method":"delete", "status":"inactive" }, { "name":"/logging/update", "method":"post", "status":"active" } 我唯一想要的是在飞行中添加/删除路线。

PassportJS – 在将有效载荷数据传递给passport.authenticate作为请求参数之前获取

有一个passport.js实现正在用于LDAP-auth工作。 现在下一步是使用Crypto-js客户端的Crypto-js ,如下所示: Client-side angular-js controller $scope.authenticate = function () { var auth = new login(); auth.username = $scope.username; auth.password = CryptoJS.AES.encrypt($scope.password); //// HERE auth.$save(function (response){ console.log(response); },function(err){ console.log(err); }); } Server-side service ….. ….. app.post('/login', passport.authenticate('ldapauth'), (req, res) => { console.log("req.user: ",req.user); req.session.username = req.user[ldap.username]; req.session.userModel = req.user; res.status(200).send({"success": 'success'}); }); ….. 在调用passport.authenticate之前在服务器端的服务上,用请求'req'validationaesencryption的密码需要被解密。 这怎么能在这里实现呢? […]

Mongoose:“TypeError:”监听器“参数必须是一个函数”连接

我试图用typecript 2.2.1,expression4.15.2和节点v7.7.2使用Mongoose ,但是当我尝试连接到MongoDB它会引发此错误: TypeError: "listener" argument must be a function at Socket.once (events.js:307:11) at Socket.connect (net.js:943:10) at Socket.connect (/home/fabian/Projects/Huis-Pils/node_modules/async-listener/index.js:76:27) at Object.exports.connect.exports.createConnection (net.js:76:35) at Connection.connect (/home/fabian/Projects/Huis-Pils/node_modules/mongodb-core/lib/connection/connection.js:399:11) at Pool.connect (/home/fabian/Projects/Huis-Pils/node_modules/mongodb-core/lib/connection/pool.js:638:16) at Server.connect (/home/fabian/Projects/Huis-Pils/node_modules/mongodb-core/lib/topologies/server.js:384:17) at Server.connect (/home/fabian/Projects/Huis-Pils/node_modules/mongodb/lib/server.js:361:17) at open (/home/fabian/Projects/Huis-Pils/node_modules/mongodb/lib/db.js:226:19) at Db.open (/home/fabian/Projects/Huis-Pils/node_modules/mongodb/lib/db.js:249:44) at NativeConnection.doOpen (/home/fabian/Projects/Huis-Pils/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:58:11) at NativeConnection.Connection._open (/home/fabian/Projects/Huis-Pils/node_modules/mongoose/lib/connection.js:531:15) at /home/fabian/Projects/Huis-Pils/node_modules/mongoose/lib/connection.js:289:11 at new wrappedPromise (/home/fabian/Projects/Huis-Pils/node_modules/async-listener/index.js:372:16) at NativeConnection.Connection.open (/home/fabian/Projects/Huis-Pils/node_modules/mongoose/lib/connection.js:288:17) […]

rxjs在错误之后立即完成观察,而不是继续

我试图通过一个observable来传输一组内容,并在第一个错误之后停止。 把它看作一系列的项目是简单的,因为它的行为是一样的。 我正在创build一个项目的数组观察 将每个项目映射到一个URL 将URL称为请求承诺 执行一个catch(),在发生错误时返回一个observable.empty() 使用RxJS 5: rx.Observable.from(array) .map(self.createUrl) .flatMap(x => { var options = { uri: url, headers: { "Content-Type": "application/json" }; return rx.Observable.fromPromise(request-promise(options)); }) .catch(() => { return rx.Observable.empty();}) .subscribe( x => console.log('success:', x), e => console.log('error'), () => console.log('complete')); 在执行此序列时,遇到第一个错误后代码将停止。 我怀疑在#4中的空观察是终止观察,但我不知道为什么。 我期望的过程是无论错误如何处理数组中的所有项目 – 最终处理所有成功的项目,并在每个错误后恢复。