Tag: node.js

git没有安装或不在PATH中

Windows,当我尝试运行npm install ,它显示: mean@1.0.0 postinstall E:\mean node node_modules/grunt-cli/bin/grunt install Running "bower:install" (bower) task Fatal error : git is not installed or not in the PATH npm ERR! weird error 1 npm ERR! not ok code 0 问题是什么? 如何解决它? 该进程是从https://github.com/linnovate/mean

使用get参数的Node.js / Express路由

比方说,我有这样的路线: app.get('/documents/format/type', function (req, res) { var format = req.params.format, type = req.params.type; }); 所以,如果我提出要求 http://localhost:3000/documents/json/mini 在我的格式和typesvariables将分别是'json'和'迷你',但如果我提出要求 http://localhost:3000/documents/mini/json 不。 所以我的问题是:我怎样才能得到不同的顺序相同的variables?

如何有效地检查variables是数组还是对象(在NodeJS&V8中)?

有没有什么办法来有效地检查NodeJS&V8中的variables是Object还是Array? 我正在为MongoDB和NodeJS编写Model,并且要遍历对象树,我需要知道对象是简单的(Number,String,…)还是复合(Hash,Array)。 看来,V8有快速内置的Array.isArray ,但如何检查对象是否是一个对象? 我的意思是像哈希{}或类的实例的复杂对象,而不是像new String() ? 通常可以这样做: Object.prototype.toString.call(object) == "[object Object]" 或这个: object === Object(object) 但是这个行动似乎并不便宜,也许还有一些效率更高? 如果它不是通用的,并且不适用于所有引擎,那么我只需要在V8上工作。

桌面应用程序仅支持oauth_callback值“oob”/ oauth / request_token

我正在尝试使用NodeJS上的OAuth进行身份validation,并且出现此错误: 获取OAuth请求令牌时出错:{statusCode:401,data:'\ n \ n桌面应用程序仅支持oauth_callback值'oob \'\ n / oauth / request_token \ n \ n'} 这是我的代码(server.js) var express = require('express'); var util = require('util'); var oauth = require('oauth'); var app = express.createServer(); // Get your credentials here: https://dev.twitter.com/apps var _twitterConsumerKey = "1"; var _twitterConsumerSecret = "2"; var consumer = new oauth.OAuth( "https://twitter.com/oauth/request_token", "https://twitter.com/oauth/access_token", _twitterConsumerKey, _twitterConsumerSecret, […]

在浏览器选项卡上共享websocket?

我们希望每个浏览器都有一个套接字,而不是浏览器中的每个标签。 我们怎样才能实现呢? 我读到了有前途的共享networking工作者。 对此的参考也是赞赏。 不幸的是,据我所知,共享的networking工作人员还没有被mozilla或者internet explorer实施。 那么在这种情况下该怎么办? 我们正在研究服务器端的node.js。

node:找不到命令

我正在设置node.js以便与Meteor,Derby或者Ember这样的框架一起工作,但是我很早就遇到了一些问题。 按照这些说明(http://www.nodebeginner.org),我安装了node,创build了一个简单的helloworld.js文件,然后在terminal运行这个命令: node path/to/file/helloworld.js 但我得到以下错误: -bash: node: command not found 我试过导航到目录,然后简单地运行: node helloworld.js 但得到相同的错误。 我对node.js是完全陌生的,不知所措。 运行OS X 10.7.5和最新版本的节点。

Node.js是否对setTimeout执行最小延迟?

在浏览器中,如果使用setTimeout调用的函数内的setTimeout那么最小延迟4ms将被强制执行。 Mozilla的开发人员wiki 描述了这种行为 ,并提到它已经在HTML5中变得标准化了 。 Node.js的setTimeout文档没有提到最小延迟。 但是, process.nextTick函数的文档将其描述为setTimeout(fn, 0)的更有效的替代方法。 这表明它可能更有效率,因为它避免了这种延迟。 否则, setTimeout(fn, 0)可能会被优化以performance相同。 像Web浏览器一样,Node.js是否对setTimeout执行最小延迟?

如何在Node.js中模拟MySQL(没有ORM)?

我使用felixge的node-mysql客户端来使用Node.js。 我没有使用ORM。 我正在testing誓言,并希望能够嘲笑我的数据库,可能使用Sinon。 由于我本身并没有真正的DAL(除了node-mysql ),我不太确定如何去做这件事。 我的模型大多是简单的CRUD,有很多getter。 任何想法如何做到这一点?

NodeJs:TypeError:require(…)不是一个函数

我想要一个文件,然后传递给一个变种。 我正在按照这个教程创build一个authentication系统。 在编写server.js文件并尝试编译后,我得到了一个bson错误,因此我改变了需要在mongoose中发布版本的那一行。 这里是我的代码和错误: server.js require('./app/routes')(app, passport); 错误 require('./app/routes')(app, passport); ^ TypeError: require(…) is not a function at Object.<anonymous> (d:\Node JS learning\WorkWarV2\server.js:38:24) at Module._compile (module.js:434:26) at Object.Module._extensions..js (module.js:452:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Function.Module.runMain (module.js:475:10) at startup (node.js:117:18) at node.js:951:3 Process finished with exit code 1 我已经读了这通常意味着requireJS没有得到正确加载,但我不知道为什么或如何解决它。 编辑由于评论: 如问, 这里是console.log(require);的结果console.log(require);

如何使用Node.js来构build静态和dynamic内容混合的页面?

我的5页网站上的所有页面都应该使用Node.js服务器输出。 大部分页面内容是静态的。 在每个页面的底部,都有一些dynamic内容。 我的node.js代码目前看起来像: var http = require('http'); http.createServer(function (request, response) { console.log('request starting…'); response.writeHead(200, { 'Content-Type': 'text/html' }); var html = '<!DOCTYPE html><html><head><title>My Title</title></head><body>'; html += 'Some more static content'; html += 'Some more static content'; html += 'Some more static content'; html += 'Some dynamic content'; html += '</body></html>'; response.end(html, 'utf-8'); }).listen(38316); 我确信这个例子有很多错误。 […]