如何使用Twilio发送短信,并等待来自手机的响应,在NodeJS中完成请求

我知道如何通过Twilio发送短信到请求正文中指定的电话号码,但是我需要一种方法来等待用户使用短信作出回应。 我需要捕获邮件正文并将其作为响应发送。 router.post('/', function(req, res){ var customerNumber = req.body.mobileNumber; var twilioNumber = process.env.TWILIO_NUMBER; client.messages .create({ to: '+1' + customerNumber, from: twilioNumber, body: 'message to user', provideFeedback: 'true', }, function(err, message){ if(err) res.send('message err: ' + err); else{ // wait 10-20 seconds for user to respond res.send("A response from the user"); } }) }); 我也知道如何听Twilio的反应,但这是行不通的,因为我需要上面的路由来回应用户在下面的路由中得到的消息。 router.post('/sms-response', […]

Openwhisk无法调用撰写postgre sql

我已经尝试了更多的小时数,而不是承认要让openwhisk函数调用Compose.io上的postgre sql datbase。 这是我的代码: 我最新的化身是这样的: function myAction(params) { return new Promise(function(resolve, reject) { console.log('Connecting to Compose database'); // console.log('Params —> ', params); var mysql = require('promise-mysql'); var fs = require('fs'); var pg = require('pg'); var request = require('request') var Promise = require('promise/lib/es6-extensions'); var connString = "postgres:xxxx"; pg.connect(connString, function(err, client, done) { console.log("connectiong..", err, client, done); […]

Node.js有效地导出非匿名函数(所以eslint停止抱怨)

使用ESLint与Airbnb风格指南如何有效地写入模块中的导出function,而不被打扰? 下列: exports.istest = function() { console.log('Test'); }; 抛出一个eslint'意外的未命名函数'警告,同时: exports.istest = function istest() { console.log('Test'); }; 似乎悲观重复。

如何使域名在特定端口下工作?

有一个Apache服务器上运行的Apache实例,它使用端口80.我也有一个nodejs应用程序使用端口8081.现在有几个域指向服务器。 Apache处理所有请求并响应所有这些请求。 我只想要其中一个域由NodeJS应用程序响应。 换句话说,我想要一个指向服务器的域来运行NodeJS应用程序。 这正是我想要做的: 这是named的configuration文件。 /etc/named.conf options { #listen-on port 53 { 127.0.0.1; }; listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; allow-query { any; }; allow-transfer { localhost; ip-address; }; /* – If you are building an AUTHORITATIVE DNS server, do NOT enable recursion. – If you […]

无法将此文件中的代码缩小

我正在编写一个我想放在npm上的JavaScript库。 我目前正在另一个项目中使用该库,我已经使用它的GitHub存储库作为依赖项添加它: "dependencies": { // … others "react-web-component": "LukasBombach/react-web-component", } 我也使用UglifyJsPlugin的UglifyJsPlugin 。 现在,当我想build立我的项目,我得到一个错误: 无法编译。 无法缩小此文件中的代码: ./packages/react-scripts/node_modules/react-web-component/src/index.js line 18:0 在这里阅读更多: https : //github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify 错误命令失败,退出代码1。 这是我的图书馆的问题。 当我从我的代码(和我的代码)中删除它编译作品。 我找不出什么问题,我的代码看起来非常简单: const ReactDOM = require('react-dom'); const retargetEvents = require('./retargetEvents'); const getStyleElementsFromReactWebComponentStyleLoader = require('./getStyleElementsFromReactWebComponentStyleLoader'); module.exports = { create: function(app, tagName, options) { const proto = Object.create(HTMLElement.prototype, { attachedCallback: { value: function() […]

如何将node_modules文件夹部署到生产服务器?

我在PHP(LAMP服务器)中制作一个非常简单的网站 (如pastebin)。 这个网站使用jquery和bootstrap。 我之前使用了bower ,但是我想切换到使用npm 。 我的目录结构是这样的: 上市 HTML 的index.php node_modules jQuery的 DIST 的jquery.js 加上几十个不必要的文件夹 引导 … 当我使用bower时,我曾经将整个bower_components文件夹上传到我的FTP服务器。 我的node_modules文件夹相当大,包含数百个文件,所以我不知道是否应该上传它? 我想我可以上传package.json并在上传后在我的web服务器的命令行上运行npm install ,但是会暴露node_modules文件夹给公众构成潜在的安全隐患?

findOneAndUpdate和push数组元素给mongoose带来错误

我的查询如下所示: const updateLikes = (item_id, userInfo) => { return new Promise((resolve, reject) => { itemLike.findOneAndUpdate({ 'item_id': item_id }, { $inc: { no_of_likes: 1 } }, { "$push": { "users": userInfo } }, { 'new': true }, (err, info) => { if (err) { reject(err); } else { if (info) { resolve(); } else { reject('no […]

使用Electron访问Angular 2应用程序中的文件系统

我知道Angular 2运行在无法访问文件系统的Web浏览器上。 不过,我使用Electron作为我的前端,并通过电子运行应用程序: "build-electron": "ng build –base-href . && cp src/electron/* dist", "electron": "npm run build-electron && electron dist" 所以我用npm run electron运行它,最后运行electron dist 。 由于我通过electron运行,而不是ng我会认为我应该能够访问文件系统。 但是,当我这样做的时候: import * as fs from 'fs' 我收到一个错误: ng:///AppModule/AppComponent_Host.ngfactory.js:5 ERROR TypeError: __WEBPACK_IMPORTED_MODULE_0_fs__.readFileSync is not a function(…) 同样,当我尝试: var fs = require('fs'); 我得到: ng:///AppModule/AppComponent_Host.ngfactory.js:5 ERROR TypeError: fs.readFileSync is not a function […]

为什么Node fs.watchFile保持testing完成?

我最近把config-js整合到Jesttesting中来获得一个可configuration的网站url和凭证,但是现在我的testing没有完全完成。 通常,我从命令行运行npm test ,testing执行,并返回命令行提示符。 用testing中的config-js,testing部分结束,但是命令行只是挂起,我必须按ctrl + c才能回到提示符。 我做了一些实验,我很确定这是由于config-j使用fs.watchFile: fs.watchFile(this.pathToConfigFile, function () { self.loadConfig(self.pathToDefaults, self.pathToConfigFile, self.region); }); 当我注释这些线,一切工作正常。 我已经尝试使用fs.watch,而不是解决它。 就这样说,我实际上并没有在我的testing中做任何改变或热重assembly置文件。 如果有帮助,这里是testing: const Config = require('config-js'); let myConfig = new Config('./my.config.js'); describe('config test', function () { it('gets the baseUrl', function() { expect(myConfig.get('testing.baseUrl')).toEqual('http://foo.com'); }); }); 这里是configuration文件的样子: module.exports = { testing: { baseUrl: "http://foo.com" } }

通过函数callback为api.ai获取json主体

我正在使用firebase来托pipe云端function,因为我需要做很多的function(大概每一个),让http请求得到json主体来从中获取数据。 但是,callback对我来说工作不太好,我已经search了一些现有的答案,但仍然卡住了这一点。 这里是代码片段,选项之前声明,如果我不把它的请求get_request_handler它工作正常: function get_request_handler(assistant, input_url, callback) { req(options, function (error, response, body) { if (!error && response.statusCode == 200) { var cookie = req.cookie('BPMSTS=' + body ); var headers = { 'Content-Type': 'application/json', 'Cookie': cookie }; var option = { url: input_url, method: 'GET', headers: headers } req(option, function(error, res, body) { assistant.ask(input_url); if […]