Tag: 节点.js

反向代理子域到同一台机器上的不同端口将引发404

我尝试过像红redbird这样的手: var proxy = require('redbird')({port: 80}); proxy.register("http://www.example.com", "http://36.154.99.115:3000"); proxy.register("http://abc.example.com", "http://36.154.99.115:3001"); proxy.register("http://xyz.example.com", "http://36.154.99.115:3002"); 和redwire如: var RedWire = require('redwire'); proxy = new RedWire({http: { port: 80 }}); proxy.http("http://www.example.com", "http://36.154.99.115:3000"); proxy.http("http://abc.example.com", "http://36.154.99.115:3001"); proxy.http("http://xyz.example.com", "http://36.154.99.115:3002"); 我可以打http://36.154.99.115:3000和http://36.154.99.115:3003成功加载各自的网页,但是当我尝试击中http://www.example.com ,我得到的是404 host not found 。 我在控制台上得到以下日志: {"name":"redbird","hostname":"ip-172-31-23-160","pid":3239,"level":30,"msg":"Proxying www.example.com/ to www.example.com:3000/","time":"2017-02-12T08:07:57.540Z","v":0} 看起来像成功,但它实际上不起作用… 运行在3000,3001和3002上的服务器正在使用DietJS 注意:我尝试了proxy.register("http://www.example.com", "http://www.facebook.com") ,它工作。

捕获node.js中较lessparsing器的exception

我在node.js中使用较less,在处理错误时我并不高兴。 我的代码如下所示: parser.parse(data, function (err, tree) { if(err){ console.log(err); res.send(500); }else{ res.header('Content-Type', 'text/css'); res.send(tree.toCSS()); } }); 我的问题是,如果我的less文件之一有语法错误,并抛出exception,崩溃的过程。 在try块中包装函数调用没有帮助。 如果在文件较less的情况下出现错误,是否可以使进程更优雅地失败?

复合服务器8888失败,“连接失败”

我想在windows机器上用nodejs启动一个项目。 我知道窗户不是正确的环境,但这就是我使用的! 我用compound server 8888启动我的服务器时遇到错误。 我通过生成所有文件 compound init photo –tpl jade –css less –db mongodb cd photo npm install -l compound generate crud album title images createdAt:date 当我意识到你可以安装化合物作为复合或复合js ,这一代运行良好(复合js安装它没有工作,但是当我安装复合它的工作 – 我认为这是相同的: – /)。 但是,当我尝试启动服务器与compound server 8888它打破了这个错误: 在开发环境中在0.0.0.0:8888上侦听的复合服务器 {PATH} \照片\ node_modules \ jugglingdb-mongodb的\ lib中\ mongodb.js:74 如果(犯错)抛出犯错; ^ 错误:无法连接到[localhost:27017] 在Server.connect.connectionPool.on.server._serverState({PATH} \ photo \ node_modules \ jugglingdb-mongodb \ […]

节点全局模块和require()中的include是否有区别?

我一直在尝试在节点中运行一个小的js脚本。 它有一个声明var less = require('less'); 。 我确信node , npm和less是全局可用的。 尽pipe,当我在我的lessCompile.js上运行node时,我得到一个'module not found'错误。 为什么? 这是我的命令行序列。 C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\node_tut>npm install -g less C:\Users\stumma\AppData\Roaming\npm\lessc -> C:\Users\stumma\AppData\Roaming\npm\node_modules\less\bin\lessc less@2.0.0 C:\Users\stumma\AppData\Roaming\npm\node_modules\less ├── graceful-fs@3.0.4 ├── mime@1.2.11 ├── promise@6.0.1 (asap@1.0.0) ├── mkdirp@0.5.0 (minimist@0.0.8) ├── source-map@0.1.40 (amdefine@0.1.0) └── request@2.47.0 (caseless@0.6.0, aws-sign2@0.5.0, forever-agent@0.5.2, json-stringify-safe@5.0.0, oauth-sign@0.4.0, stringstream@0.0.4, tunnel-agent@0.4 .0, node-uuid@1.4.1, mime-types@1.0.2, qs@2.3.3, combined-stream@0.0.7, tough-cookie@0.12.1, […]

内存node.js Buffer内部使用多less个实际字节来存储1个逻辑字节的数据?

Node.js文档指出: 缓冲区类似于整数数组,但对应于V8堆外部的原始内存分配。 我是正确的,所有的整数都表示为内部在JavaScript中的64位浮点数? 这是否意味着在Node.js缓冲区中存储1个字节实际上需要8个字节的内存? 谢谢

NodeJS导入错误

我正在尝试使用resemblejs库( http://huddle.github.io/Resemble.js/ )来比较两个图像。 但是,当我创build了一个目录,并添加了nodejs test.js作为依赖,但是当我尝试运行以下: nodejs test.js ,我得到以下错误 var api = resemble(fileData).onComplete(function(data){ ^ ReferenceError: resemble is not defined 我之前从来没有使用过NodeJS,所以它可能非常简单。 有任何想法吗?

节点handbrakejs运行代码,但不输出

所以我有以下代码: var hbjs = require('handbrake-js'); var encodingOptions = { input: media.file.path, output: media.targetDir+"helloWorld.m4v", quality: 17, optimize: '', encoder: "x264" }; hbjs.spawn(encodingOptions) .on("begin",function(){ console.log('begin') }) .on("error", function(err){ // invalid user input, no video found etc console.log('error!') }) .on("progress", function(progress){ console.log( "Percent complete: %s, ETA: %s", progress.percentComplete, progress.eta ); }) .on("complete", function (complete) { console.log('hello'); }) 此代码运行,一旦完成,我得到以下控制台消息: […]

摩卡/ Should.js使用asynchronousfunction

我是JavaScripttesting框架的新手。 我想做一点优化,但遇到一些问题。 该项目正在使用should.js 这里是我原来的testing用例的简化版本: describe('Simple', function() { describe('Test', function() { it('should do something', function(done) { somePromise.then(function(data) { data.should.above(100); done(); }); } it('should do something else but alike', function(done) { somePromise.then(function(data) { data.should.above(100); done(); }); } } }); 我试图这样做: var testFunc = function(data) { it('should do something', function(done) { data.should.above(100); done(); }); } describe('Simple', function() { […]

e2e与jenkins,selenium网格和量angular器testing

我正在尝试使用Jenkins,Selenium和Protractor来构build我的testing环境。 我决定使用selenium插件(selenium网格)在远程机器(节点)之间调度testing。 我到目前为止所取得的成就是build立selenium中枢与节点之间的联系。 Jenkins上安装的Node.js版本是5.12.0,量angular器是3.3.0。 我还安装了npm chromedriver并在protractor.config.js中设置了这个驱动程序的path,如下所示: chromeDriver: '/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/chromedriver/bin/chromedriver' 节点正在运行selenium独立服务器,全局安装npm。 当我执行我的protractor.config.js文件时,我有以下错误: protractor /u01/apps/jenkins/data/workspace/Servers/testApp/protractor.conf.js [14:49:08] I/direct – Using ChromeDriver directly… [14:49:08] I/launcher – Running 1 instances of WebDriver /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329 return callbackFn(this.value_); ^ Error: Server terminated early with status 127 at Error (native) at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/remote/index.js:210:20 at Promise.invokeCallback_ (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14) at TaskQueue.execute_ (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14) at TaskQueue.executeNext_ (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21) at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2652:27 at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7 […]

使用Underscore / Lodash在JavaScript中完成一个非变异反向拖尾的最佳方法

我是我的node.js项目lodash /下划线的狂热用户,我发现自己的情况下,我需要以类似于下面的代码的方式从右到左recursion遍历数组(假设所有调用是同步的): function makeDir(pathArray) { var unsulliedPath = clone(pathArray); var lastGuy = pathArray.pop(); var restOfEm = pathArray; if dirExists(unsulliedPath) { console.log("Your job is done!"); } else { makeDir(restOfEm); makeDir(unsulliedPath); } } 然而,克隆和改变pathArray参数会让我感到困惑。 所以我可以这样做: function makeDir(pathArray) { var lastGuy = _.last(pathArray); // EITHER I could… var restOfEm = _(pathArray).reverse().tail().reverse().value(); // OR I could do… var restOfEm […]