Tag: node.js

如何在谷歌数据存储查询filter处理浮点?

我一直在使用Google DataStore尝试将查询从SQL数据库迁移到DataStore。 我在Node中工作,试图在一个实体上过滤。 该实体具有以下字段。 Exchange: String Threshold: Floating Point Number Pairing: String Userid: String 我可以使用Google云端平台Web视图的按类别查询function成功查询实体。 我目前的代码实现似乎没有返回我想要的正确的响应,虽然我能够作出请求,当我离开阈值filter行。 也build立了适当的指标。 const query = datastore.createQuery('notifications_info') .filter('exchange', '=', objectToRequest.exchange) .filter('threshold', '<=', 0) .filter('threshold', '>', -3) .filter('pairing', '=', objectToRequest.pairing); datastore.runQuery(query,function(error, results){ if(error){ console.log(error); } else if (results){ console.log(results); callback(error, results); } }); 对象要求 var objectToRequest = { exchange: 'gdax', time_interval: 60 […]

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

今天开始学习节点,我几乎肯定我的用户没有被正确注销,我不明白为什么。 为了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 }, […]

如何使用其他节点项目的node_modules目录

我有一个想法。 比方说,我正在学习angular度,我创造了许多testing项目。 用命令ng new project_name 。 每次我启动这个命令,都需要很多时间来下载和安装node_modules。 我在想什么,我可以使用ng new project_name –skip-install创build项目来创build项目并跳过节点模块安装,稍后我将在我的项目configuration文件(systemjs.config.js) paths: { // paths serve as alias 'npm:': 'node_modules/' <– here I change the path to some other directory }, 使用已安装模块的其他某个项目的node_modules目录。 我试图实现的不是一次又一次地下载相同的模块,也不会减慢我的项目创build时间。

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

发送一个http请求到一个graphql api时“parsingJSON的问题”

我试图发送一个HTTP请求到Githubs graphql API(V4)。 我的猜测是我的查询格式是错误的。 下面的代码用于向api发送POST请求。 app.get('/fetch-data', function(req, res, next) { const access_token = settings.dev.TOKEN; const query = {query: { viewer: { 'login': 'muckbuck' } }}; const options = { uri: 'https://api.github.com/graphql', method: 'POST', headers: { 'Accept': 'application/json', 'Authorization': "Bearer " + access_token, 'User-Agent': 'request', 'contentType': "application/graphql", }, data: query }; function callback(error, response, body) { […]

Webpack-dev-server找不到要提交的文件

我只是从webpack文档复制粘贴webpack-dev-server + express设置,但是它不起作用,因为服务器找不到要提供的文件。 这个设置有什么问题? server.js const express = require('express'); const webpack = require('webpack'); const webpackDevMiddleware = require('webpack-dev-middleware'); const app = express(); const config = require('../webpack.config.js'); const compiler = webpack(config); app.use(webpackDevMiddleware(compiler, { publicPath: config.output.publicPath })); /*app.use('/',express.static('public')) it works when used insted of webpack dev middleware */ // Serve the files on port 3000. app.listen(3000, function () […]

Sinonfunction存根:如何在模块内调用“自带”function

我正在为node.js代码编写一些unit testing,并使用Sinon通过存根函数调用 var myFunction = sinon.stub(nodeModule, 'myFunction'); myFunction.returns('mock answer'); nodeModule看起来像这样 module.exports = { myFunction: myFunction, anotherF: anotherF } function myFunction() { } function anotherF() { myFunction(); } Mocking对于像nodeModule.myFunction()这样的用例显然nodeModule.myFunction() ,但是我想知道如何在用nodeModule.anotherF()调用时如何在另一个F()内模拟myFunction()调用?

电子协议处理程序不能在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) […]

查看Slack合规性档案

我需要一些帮助来查看和search闲置的档案。 我有一个我试图通过的档案的zip文件(请参阅下面的详细信息)。 我发现这个项目并克隆它。 https://github.com/dting/slack-archive-viewer 。 我安装了节点和postgres。 我在文件夹slack-archive-viewer中创build了一个.env文件:具有以下细节: APP_SECRET= APP_SECRET ( I set this = to Client Secret listed in slack – to connect to the slack API) SLACK_ID =SLACK_ID ( I set this to the slack Client ID without quotes) SLACK_SECRET= SLACK_SECRET (i set this to the slack Verification Token ) DOMAIN = http://localhost:9000 这些设置是正确还是需要使用其他设置,我会在哪里find正确的设置? […]