ECONNFUSED在应用程序中进行GET请求时,API成功返回JSON

我正在用React编写节点应用程序,使用node-postgres和superagent进行后端调用。 比方说,我正在做一个GET请求,并使用返回的JSON来填充学生表。 我的API看起来像这样: import pg from 'pg'; import Router from 'express'; let router = new Router(); let conString = "postgres://user:pass@localhost/db_name"; router.get('/getStudents', function(req, res) { var results = []; pg.connect(conString, function(err, client, done) { if (err) { done(); console.log(err); return res.status(500).json({success: false, data: err}); } var query = client.query('SELECT first_name, last_name, email FROM students'); query.on('row', function(row) […]

下一个刻度覆盖function函数将被调用

我需要重写下面的代码 这个函数将在下一个勾号中执行 req.nextTick = typeof setTimeout !== 'undefined' ? function (fn) { setTimeout(fn, 5); } : function (fn) { fn(); }; 有了这个, window.require.nextTick = function(fn) { fn(); }; 由于该函数将被立即调用,在这种情况下,它将不会被执行下一个滴答声?

如何在gulpfile.js中使用babel-polyfill

在巴贝尔文件中,他们只是说包括import "babel-polyfill"; 所以,我可以使用ES6生成器,但是,当我包括在我的gulpfile.js行后,我仍然产生一个exception: Uncaught ReferenceError: regeneratorRuntime is not defined这是我的gulpfile.js import 'babel-polyfill'; var gulp = require("gulp"), babel = require("gulp-babel"), concat = require('gulp-concat'), rename = require('gulp-rename'), uglify = require('gulp-uglify'); gulp.task("babel", function() { return gulp.src(jsSrc) .pipe(concat('Main.js')) .pipe(babel()) .pipe(gulp.dest(jsDest)) .pipe(rename('Main-min.js')) .pipe(uglify()) .pipe(gulp.dest(jsDest)); }); jsSrc有maines6.js和其他.js文件。 在maines6.js这里是我的发电机: function* anotherGenerator(i) { yield i + 1; yield i + 2; yield i + […]

用Node.js和Express显示一个JSON数据集

首先,我想指出,我对Node.JS非常陌生。 我试图使用NodeJS来创build一个包含多个表和信息的页面。 我的问题是,我无法从SQL查询结果到HTML表格。 目前我使用快递将数据发送到HTML页面。 我使用的代码: var http = require('http'); http.createServer(function(req, res) {}); var mysql = require("mysql"); var express = require('express'); var app = express(); console.log('Creating the http server'); con.query('SELECT id ,name FROM customer', function(err, rows, fields) { console.log('Connection result error '+err); console.log('num of records is '+rows.length); app.get('/', function (req, res) { res.send(rows); }); }); app.listen(3002, […]

Google API NodeJS:calendar.events.watch获取错误push.webhookUrlNotHttps或pushWebhookBadDomain

我已经按照https://developers.google.com/google-apps/calendar/v3/push (我认为)中所需的所有设置,我正在尝试注册我的callbackURL来观看事件,并使用以下代码: calendar.events.watch({ auth:jwtClient, resource: { id: "yourChannelId", type: 'web_hook', address: "https://api.mysite.com/notifications" }, calendarId: "mycalendarId" }, function(error, response) { if (error) { console.log(error); return; } console.log(response); }); 我得到错误message: 'No valid domain for WebHook callback: https://https://api.mysite.com', reason: 'pushWebhookBadDomain' 。 如果我尝试将地址设置为“api.mysite.com/notifications”(因为https看起来是重复的),那么我会收到错误message: 'WebHook callback must be HTTPS: api.mysite.com/notifications', reason: 'push.webhookUrlNotHttps' 任何人都可以帮我吗? 谢谢

Angular2的自定义渲染器

我正在尝试使用Angular2的自定义渲染器。 我已经build立了一个简单的示例项目 ,我想在Node.js上运行一个最小的Angular2应用程序( AppComponent )。 我已经实现了一个自定义的DomAdapter和一个自定义的渲染器 (只是一个应该login到控制台的虚拟),然后我尝试在一些自定义引导代码中将所有东西连接在一起。 目前,我遇到以下错误消息: Error: No precompiled component AppComponent found at new BaseException (/home/ralf/git/node-angular-example/node_modules/angular2/src/facade/exceptions.js:15:23) at Compiler_.compileInHost (/home/ralf/git/node-angular-example/node_modules/angular2/src/core/linker/compiler.js:47:19) at DynamicComponentLoader_.loadAsRoot (/home/ralf/git/node-angular-example/node_modules/angular2/src/core/linker/dynamic_component_loader.js:101:31) at di_1.provide.useFactory (/home/ralf/git/node-angular-example/node_modules/angular2/src/core/application_ref.js:29:47) at Injector._instantiate (/home/ralf/git/node-angular-example/node_modules/angular2/src/core/di/injector.js:763:27) at Injector._instantiateProvider (/home/ralf/git/node-angular-example/node_modules/angular2/src/core/di/injector.js:714:25) at Injector._new (/home/ralf/git/node-angular-example/node_modules/angular2/src/core/di/injector.js:703:21) at InjectorInlineStrategy.getObjByKeyId (/home/ralf/git/node-angular-example/node_modules/angular2/src/core/di/injector.js:216:33) at Injector._getByKeyDefault (/home/ralf/git/node-angular-example/node_modules/angular2/src/core/di/injector.js:899:37) at Injector._getByKey (/home/ralf/git/node-angular-example/node_modules/angular2/src/core/di/injector.js:845:25) 有人可以解释这是什么意思,缺less什么? 更新: Tobias Bosch指出, COMPILER_PROVIDERS失踪了。 但是,添加它们后,我得到另一个错误: Error: DI Exception at […]

Object.assign和刚分配的区别

我想知道这个之间的区别: Object.assign(otherObject, { someNewProperty: '' }); 和 otherObject.someNewProperty = ''; 而且哪一个更快? 谢谢。

将数据安全地存储在Node CLI应用程序中

我目前正在编写一个NodeJS命令行应用程序。 该应用程序进行API调用,并返回一些数据给用户。 鉴于这是一个公共API,用户需要一个API令牌。 这个CLI将通过npm i -g super-cool-api-cli在用户的机器上全局安装。 用户第一次运行CLI时,系统会提示input令牌,然后将其存储起来,以便随后每次运行令牌时都不需要input令牌。我也为用户提供了一种重置它的方法。 我将它存储在我的CLI模块的实际目录中,正如所述,它是全局安装的,它看起来像这样: fs.writeFile( __dirname+'/.token.json', JSON.stringify( { "token": token }, null, 2 ), 'utf8', (e)=>{ // error handling and whatever }); 我将文件命名为.token.json ,使用一个点来默认隐藏文件。 我想我问的是,如果在NodeJS命令行应用程序中存储更好/更安全的方式来存储敏感信息,那么您将运行多次。 我想过使用像环境variables这样的东西,但似乎在这个过程结束时会过期。 安全考虑是我有点缺乏的一项技能,但是大大希望了解更多,所以提前谢谢你的提示。

简单的方法来增加任何更新查询的Mongoose文档版本?

我想开始利用Mongoose文档版本控制(__v key)。 我有一个问题,实际上增加版本的价值,然后我发现你必须添加this.increment()执行查询时。 有没有办法自动递增? 现在,我只是把它添加到前置中间件中进行更新types的查询: module.exports = Mongoose => { const Schema = Mongoose.Schema const modelSchema = new Schema( { name: Schema.Types.String, description: Schema.Types.String } ) // Any middleware that needs to be fired off for any/all update-type queries _.forEach( [ 'save', 'update', 'findOneAndUpdate' ], query => { // Increment the Mongoose (__v)ersion for any […]

无法使用“下划线”来使用parsing服务器

我刚刚迁移了一个分析服务器,除云代码之外,一切正常。 我已经了解到,这是因为在我的main.js中,我需要库“Underscore”。 这是我的云代码function: Parse.Cloud.define("ReadyUp", function(request, response) { var _ = require('underscore'); var fbid = request.user.get("fbid"); var query = new Parse.Query("Spel"); query.equalTo("lobby", fbid); query.find().then(function(results) { _.each(results, function(spel) { spel.addUnique("ready", fbid); }); return Parse.Object.saveAll(results); }).then(function(result) { response.success(result); }, function(error) { response.error(error); }); }); 代码在迁移之前没有任何错误。 我猜测的要求没有find正确的文件夹。 给你文件夹结构看起来像这样: Cloudcode位置:mainfolder-> cloud-> main.js 下划线库:mainfolder-> node_modules->下划线(文件夹) 代码是错误的还是文件夹的结构有问题? 提前致谢! /马丁