Tag: javascript

Request-Promise使用async / await抛出“no auth mechanisms defined”

我只是尝试asynchronous/等待request-promise并遇到这个错误: RequestError: Error: no auth mechanism defined at new RequestError (node_modules/request-promise-core/lib/errors.js:14:15) at Request.plumbing.callback (node_modules/request-promise-core/lib/plumbing.js:87:29) at Request.RP$callback [as _callback] (node_modules/request-promise-core/lib/plumbing.js:46:31) at self.callback (node_modules/request/request.js:188:22) at Auth.onRequest (node_modules/request/lib/auth.js:133:18) at Request.auth (node_modules/request/request.js:1360:14) at Context.<anonymous> (test/routes.js:37:41) From previous event: at Request.plumbing.init (node_modules/request-promise-core/lib/plumbing.js:36:28) at Request.RP$initInterceptor [as init] (node_modules/request-promise-core/configure/request2.js:41:27) at new Request (node_modules/request/request.js:130:8) at request (node_modules/request/index.js:54:10) at Context.<anonymous> (test/routes.js:37:24) 这是我最近build立的API端点,它应该在MongoDB中创build一个新的用户。 它使用Passport策略提供的基本身份validation,并且使用Postmantesting了它的工作原理。 我不确定为什么这个错误被抛出。 […]

async调用基类的构造函数之后,无法在子类上设置属性。 NodeJS v8.2.1

你可以请帮忙了解什么可能是错误,而在父类的callback中使用承诺,然后尝试设置子类的属性? 我正在使用nodejs v8.2.1 这里是基类的例子: class CGLBase extends CAuthClient { constructor(req, res) { return new Promise(resolve => { super(req, res, (authClient) => { this.setAuthClient(authClient); resolve(this); }); }); } setAuthClient(authClient) { //setting authClient (this.auth will contain property) } } 这里的子类的例子: class СSheet extends CGLBase { constructor(document, urlRequest, urlResponse) { super(urlRequest, urlResponse); this.document = document; this.someAnotherProp = "some […]

如何确定用户在使用护照时注销?

今天开始学习节点,我几乎肯定我的用户没有被正确注销,我不明白为什么。 为了login用户,我在路由文件中写了下面的代码 app.post('/api/signup', passport.authenticate('local-signup', function(err, res, req) { console.log(res); })); 然后在另一个文件这个代码来处理我的用户login的逻辑 passport.serializeUser(function(user, done) { console.log("serializeUser"); console.log(user); done(null, user.id); }); passport.deserializeUser(function(id, done) { console.log("deserializeUser"); console.log(id); User.findById(id, function(err, user) { done(err, user); }); }); passport.use('local-signup', new LocalStrategy( { usernameField: 'username', passwordField: 'password', passReqToCallback: true }, function(req, username, password, done) { console.log(req.sessionID); process.nextTick(function() { User.findOne({ 'local.username': username }, […]

JavaScript:使用时区将UTC时间转换为本地时间

我有一个UTCdate时间string和时区名称。 我从第三方API获取这个。 我需要使用JavaScript / NodeJS将UTC时间转换为该时区的本地时间以及获取该时区的当前时间。 有没有相同的图书馆/方法? var timezone = "America/New_York";//This will always be in Olson format. var UTCTime = "2017-09-03T02:00:00Z"; var localTime; //I need to find the equivalent of UTCTime for America/New_York var currentTime; //Current time of time zone America/New_York

电子协议处理程序不能在Windows上工作

我试图注册一个协议处理程序使用app.setAsDefaultProtocolClient ,我已经得到它在macOS上工作正常,但在Windows 10我得到一个对话说 Error launching app Unable to find Electron app at 'C:\Program Files(x86)\Google\Chrome\Application\60.0.3….. Ect Cannot find module 'C:\Program Files(x86)\Google\Chrome\Application\60.0.3….. Ect 是否正确查看Chrome \ Application文件夹? 如果我使用npm start或使用electron-packager打包的应用程序运行,我会得到同样的错误。 有什么我想念我需要configuration为Windows? 像Mac上的plist? 我一直在寻找,但似乎无法find任何东西。 让我知道任何信息,我可以添加到帮助。

如何closuresAngular 2/4 +和Socket.io中的websocket

我试图创build一个使用websockets的应用程序,但是遇到了可怕的“多重连接”问题,每次页面重新加载而不是closures并重新打开一个新的websocket,另一个连接只是添加到列表中。 我的问题是,如果有人知道从Angular 2/4 +closuresSocket.io websocket的最佳/正确的方式。 至于代码,这是我所拥有的: service.ts getUserSocket(userID: string): Observable<any> { return new Observable(_Observer => { // Setup the socket namespace subscription this.UserSocket = io(NTC_API_URL + `/user/${userID}`, { secure: true }); this.UserSocket.on('message', _Message => { console.log(_Message); }) }) } closeUserSocket() { this.UserSocket.disconnect(); this.UserSocket.close(); } component.ts ngOninit() { // Setup the User Socket this.UserSocket = this._UsersService.getUserSocket(this.currentUser.userID) […]

服务器和客户端在socket.io中的“on”和“emmit”不同

我很难理解服务器何时“发送”数据,何时客户端“获取”数据,反之亦然。 代码是在他们的例子 在nodejs的index.js中 // server side var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); }); io.on('connection', function(socket){ console.log('a user connected'); // create chat message socket.on('chat message', function(msg){ io.emit('chat message', msg); console.log('message: ' + msg); }); socket.on('disconnect', function(){ console.log('user disconnected'); }); }); http.listen(3000, function(){ console.log('listening on […]

为什么模块导出variables是空的?

我是nodejs的新手。 这是我的.js文件。 我试图将audioDatavariables暴露给其他函数。 audioDatavariables的值在函数外部是空的。 当我在函数内部打印时,我看到了这个值。 什么可能是错的? 'use strict'; var asyncrequest = require('request'); var xml2js = require('xml2js'); var parseString = xml2js.parseString; var audioData = []; asyncrequest("http://example.com/feed", function(error, responsemeta, body) { parseString(body, function(err, result){ var stories = result['rss']['channel'][0]['item']; console.log("Total stories: " + stories.length); stories.forEach(function(entry) { var singleObj = {} singleObj['title'] = entry['title'][0]; singleObj['value'] = entry['enclosure'][0].$.url; audioData.push(singleObj); }); […]

Node.js:如何获取错误对象中的不正确的字段

我在下面的架构中有独特和必填字段。 当其中的任何一个留空时,将返回一个错误。 如何在Error对象中find有关哪些字段留空的信息? var mongoose = require('mongoose'); var uniqueValidator = require('mongoose-unique-validator'); var Schema = mongoose.Schema; var kullaniciShema = new Schema({ gsm: String, email: String, kullaniciAdi: { type: String, required: true, unique: true }, sifre: { type: String, required: true}, }, { collection: 'kullanici' }); kullaniciShema.plugin(uniqueValidator); var Kullanici = mongoose.model('Kullanici', kullaniciShema); module.exports = Kullanici; 下面是我提交的数据保存到数据库的控制器。 一些传入的数据是空的,所以我得到一个空白字段的错误。 […]

仅在mongoDB Node JS上存在集合时才显示给客户端

我有这个在Mongoose上定义的模式模型: var mongoose = require("mongoose"); var IngredientSchema = new mongoose.Schema({ name:String, number:Number, exist:Boolean, photoName:String }) module.exports = mongoose.model("Ingredient", IngredientSchema); 而且我想在网页上显示不同的结果,这取决于数据库中是否已经创build了一个成分。 这是我到目前为止(但它不起作用): <!– Check if inventory is empty or not, and display accordingly –> <% if ( ! ingredients) { %> <p>Add you first ingredient to the inventory !!</p> <% } else { %> <% ingredients.forEach(function(ingredient) […]