函数返回后仍然运行

当用户单击button时,我将添加一个颜色select器到我的Electron应用程序中.click .click()触发我的函数,该函数关注input(隐藏的opacity: 0; height: 0px; width: 0px; ),作为用户点击( .blur() )时获取光标位置的颜色的代理。 然后它将该颜色放在另一个input字段中并返回。 但是,如果用户再次单击返回的input字段,然后单击, .blur()仍然会触发。 为什么是这个,我该如何防止呢? <input class="clickProxy" style="opacity: 0; height: 0px; width: 0px;" /> $('.color_picker').click(function(){ getColorAtPointer(); }); function getColorAtPointer(){ $('input[name="colorSample"]').focus(); $('input[name="colorSample"]').blur(function(){ var mouse = robot.getMousePos(); $('input[name="colorSample"]').val('#'+robot.getPixelColor(mouse.x, mouse.y)); return; }); } 谢谢!

nodejs如何将node_modules目录提供给前端进行访问?

如果不使用Browserify或Webpack等打包软件,我在nodejs中有一个简单的服务器。 var express = require('express'); var bodyParser = require('body-parser'); var request = require('request'); var app = express(); app.use(bodyParser()); app.use(express.static('public')); app.use(express.static('node_modules')); app.post('/api/searchjob', function (req, res) { res.json({data: "hello"}); }); app.get('/', function(req,res) { res.sendfile('public/index.html'); }); app.get('/*', function(req, res){ res.redirect('/'); }) app.listen(process.env.PORT || 3000, function () { console.log('Example app listening on port 3000!') }); 我希望前端也可以访问一些node_modules包,我该怎么办? 我的index.html文件在“public”目录下,文件夹结构如下所示: ├── README.md […]

无法读取nodeJS中的URL编码

我在nodeJS中使用快速框架,并尝试发送电子邮件激活链接,但是当我激活链接的URL编码和expression路由无法读取和发送到404错误页面。 Url: xxx.com/#/user/543fe901b43083207ff0f863c07135b6/xxx.x@gmail.com On click to URL: xxx.com/#%2Fuser%2F543fe901b43083207ff0f863c07135b6%2Fxxx.x@gmail.com 你能帮我解决我做错了什么,或者我错过了什么吗? 提前致谢。

可靠地确定使用shell(cmd,bash等)来运行node.js脚本

正如标题所述,我想确定使用shell( cmd , bash等)来运行node.js脚本(从脚本中)。 当用os模块检测操作系统可以给出一些线索的时候,一些实例是不够的,比如像在GitBash或者Cygwin这样的terminal上通过win32 bash执行。 有没有这个信息的process对象的某个属性? *编辑:虽然process.env.SHELL是一个选项,但在使用某些terminal时,并不总是可以填充,也可能是undefined

从Node.js服务器本地访问JSON POST有效内容

考虑下面的一个Node.js服务器的HTTP POST调用: curl -H "Content-Type: application/json" \ -X POST \ -d '{"jsonKey":"jsonValue"}' \ 'http://localhost:8080?abcd=efgh' 我想访问POST请求的URL参数和JSON负载。 通过导入url.parse访问URL参数非常简单: var server = http.createServer(function(req, res) { // Parse the params – prints "{ abcd: 'efgh' }" var URLParams = url.parse(req.url, true).query; console.log(URLParams); // How do I access the JSON payload as an object? } 但是,如何使用本地Node.js库(不包括任何npm导入)来访问JSON负载? 我试过了什么 打印req到console.log ,但没有findPOST对象 阅读req的文档,这是typeshttp.IncomingMessage

表示不回应路线

我正在使用nodejs并为api端点表示,我正在使用app.use来处理一个路由,但是不pipe我做了什么,它都没有响应。 var express = require("express"); var mongoose = require('mongoose'); var path = require("path"); var favicon = require("serve-favicon"); var http = require('http'); var app = express(); var config = require('./conf/config'); var PORT = config.PORT; mongoose.connect(config.MONGODB); //route handlers app.use('/', function(req, res) { console.log("Hello"); }); var server = http.createServer(function(req, res) { console.log("Request received", req.url); }); server.listen(PORT); console.log("Server running […]

如何从节点模块导出asynchronousfunction

我正在尝试编写一个节点模块来处理我的各种数据库调用。 我想尽可能使用asynchronous/等待,但是我遇到了一些问题。 我一直在使用承诺,并导出这些function很好。 例: function GetUsernames() { return new Promise(function (resolve, reject) { sql.connect(config).then(function () { new sql.Request() .query("SELECT [UserName] FROM [Users] ORDER BY [LastLogin] ASC").then(function (recordset) { resolve(recordset); }).catch(function (err) { reject(err); }); }); }); } 然后我输出以下内容: module.exports = { GetUsernames: GetUsernames, GetScopes: GetScopes, UpdateToken: UpdateToken, SetOwner: SetOwner }; 但是,如何使用async函数来执行node7中的async / await? 我还只是答应了吗? 我试过这样做,但是当我在代码中调用它时,它不起作用。 […]

不完整的节点HTTP.Response

我的应用程序build立一个需要连接的自定义整数数组,以创build经济数据的dynamic请求。 一旦我的variables选项被创build,我通过一个http请求推送它,并尝试parsing响应,在那里我得到一个错误 – SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) 当我使用我的代码来读取正文时,响应提前切断,并且在console.log()中没有得到完整的响应。 我已经testing了请求值,并将结果放在我的search栏中,并取得了积极的结果。 任何想法,为什么身体的反应被缩短? 我需要从这个请求中读取所有的数据,并在parsing的时候得到错误。 这是代码 – var options = { host: 'api.eve-central.com', port: 80, path: '/api/marketstat/json?typeid=18&typeid=19&typeid=20&typeid=21&typeid=22&typeid=34&typeid=35&typeid=36&typeid=37&typeid=38&typeid=39&typeid=40&typeid=41&typeid=42&typeid=43&typeid=44&typeid=45&typeid=49&typeid=50&typeid=51&typeid=52&typeid=164&typeid=165&typeid=166&typeid=178&typeid=179&typeid=180&typeid=181&typeid=182&typeid=183&typeid=184&typeid=185&typeid=186&typeid=187&typeid=188&typeid=189&typeid=190&typeid=191&typeid=192&typeid=193&typeid=194&typeid=195&typeid=196&typeid=197&typeid=198&typeid=199&typeid=200&typeid=201&typeid=202&typeid=203&typeid=204&typeid=205&typeid=206&typeid=207&typeid=208&typeid=209&typeid=210&typeid=211&typeid=212&typeid=213&typeid=215&typeid=216&typeid=217&typeid=218&typeid=219&typeid=220&typeid=221&typeid=222&typeid=223&typeid=224&typeid=225&typeid=226&typeid=227&typeid=228&typeid=229&typeid=230&typeid=231&typeid=232&typeid=233&typeid=234&typeid=235&typeid=236&typeid=237&typeid=238&typeid=239&typeid=240&typeid=241&typeid=242&typeid=243&typeid=244&typeid=245&typeid=246&typeid=247&typeid=248&typeid=249&typeid=250&typeid=251&typeid=252&typeid=253&typeid=254&usesystem=30000142', method: 'GET' } function requester(options) { http.request(options, function (res) { //console.log('STATUS: ' + res.statusCode); //console.log('HEADERS: ' + JSON.stringify(res.headers)); res.setEncoding('utf8'); res.on('data', function (chunk) { console.log('BODY: ' + chunk); […]

定制泊坞窗图像不运行postgres

我正在尝试为circleci v2创build自己的自定义泊坞窗文件。 但是,我遇到了postgres服务器没有运行的问题。 我已经运行service postgresql start没有可用。 我得到的消息是: psql: could not connect to server: Connection refused Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? Dockerfile: FROM ubuntu:16.04 ENV NODEJS_VERSION 6 ENV POSTGRESQL_VERSION 9.6 RUN apt-get update && apt-get -y install curl RUN curl -sL https://deb.nodesource.com/setup_$NODEJS_VERSION.x | bash – RUN apt-key adv […]

我无法获取AMQP发布和订阅,从IBM MQ v9.0.1.0开始使用Node JS v6和mqlight v2.0运行

我想获得下面的示例片段发布和订阅,我不能让它与节点JS 6和mqlight v2.0运行 https://www.npmjs.com/package/mqlight?cm_mc_uid=47189062138014548006442&cm_mc_sid_50200000=1490060435 // Receive: var mqlight = require('mqlight'); var recvClient = mqlight.createClient({service: 'amqp://user:user@localhost:5672'}); recvClient.on('started', function() { recvClient.subscribe('/TEST/#','sub1'); recvClient.on('message', function(data, delivery) { console.log(data); }); }); // Send: var sendClient = mqlight.createClient({service: 'amqp://user:user@localhost:5672'}); sendClient.on('started', function() { sendClient.send('TEST'); }); 我使用节点js v6运行示例代码mqlight 2.0 $node mqlight_sample.js events.js:160 throw er; // Unhandled 'error' event ^ SecurityError: AMQXR0100E: A connection […]