Tag: node.js

rest与Express.js嵌套路由器

假设我想让REST端点看起来像这样: /user/ /user/user_id /user/user_id/items/ /user/user_id/items/item_id 每个CRUD都是有道理的。 例如,/ user POST创build一个新用户,GET获取所有用户。 / user / user_id GET只提取一个用户。 项目是用户特定的,所以我把它们放在user_id下,这是一个特定的用户。 现在要使Express路由模块化,我做了几个路由器实例。 有一个用户的路由器,并为该项目的路由器。 var userRouter = require('express').Router(); userRouter.route('/') .get(function() {}) .post(function() {}) userRouter.route('/:user_id') .get(function() {}) var itemRouter = require('express').Router(); itemRouter.route('/') .get(function() {}) .post(function() {}) itemRouter.route('/:item_id') .get(function() {}) app.use('/users', userRouter); // Now how to add the next router? // app.use('/users/', itemRouter); item的URL是user的URL分层结构的后代。 […]

nodeJscallback简单的例子

任何人都可以给我一个简单的nodeJscallback的例子,我已经在很多网站上search过相同的东西,但是不能正确理解,请举个简单的例子。 getDbFiles(store, function(files){ getCdnFiles(store, function(files){ }) }) 我想要做那样的事情

E:无法find包mongodb组织

我正在尝试下载mongodb,我正在按照此链接上的步骤进行操作。 但是当我走到这一步时: sudo apt-get install -y mongodb-org 我得到以下错误: Reading package lists… Done Building dependency tree Reading state information… Done E: Unable to locate package mongodb-org //This is the error 为什么会发生这种情况,是否有解决办法?

如果有基本授权,如何在Node.js中使用http.client

按照标题,我该怎么做? 这是我的代码: var http = require('http'); var client = http.createClient(80, 'www.example.com'); // to access this url i need to put basic auth. var request = client.request('GET', '/', {'host': 'www.example.com'}); request.end(); request.on('response', function (response) { console.log('STATUS: ' + response.statusCode); console.log('HEADERS: ' + JSON.stringify(response.headers)); response.setEncoding('utf8'); response.on('data', function (chunk) { console.log('BODY: ' + chunk); }); });

Npm安装不能find模块'semver'

我不能在NodeJS中使用命令提示符使用npm install 。 运行npm install时出现这个错误: module.js:339 throw err; ^ Error: Cannot find module 'semver' at Function.Module._resolveFilename (module.js:337:15) at Function.Module._load (module.js:287:25) at Module.require (module.js:366:17) at require (module.js:385:17) at Object.<anonymous> (C:\Users\admin\AppData\Roaming\npm\node_modules\npm\l ib\config\defaults.js:6:14) at Module._compile (module.js:435:26) at Object.Module._extensions..js (module.js:442:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:311:12) at Module.require (module.js:366:17) 请帮帮我。

如何查找search/查找npm包

有什么方法可以findnpm软件包? 下面是从下面的答案编译的社区维护列表。 NPM具体 在控制台中, npm search <keyword> https://www.npmjs.org/ http://eirikb.github.com/nipster/通过https://stackoverflow.com/a/10571033 http://node-modules.com/通过https://stackoverflow.com/a/13593402 https://nodejsmodules.org/通过https://stackoverflow.com/a/17821476 http://npmsearch.com/通过https://stackoverflow.com/a/34471018 通用 http://github.com https://libraries.io 死 http://browsenpm.org/通过https://stackoverflow.com/a/24338500 https://github.com/joyent/node/wiki/modules http://toolbox.no.de/ aka http://nodetoolbox.com/ http://packagefinder1-enome.dotcloud.com/

如何在不使用npm的情况下安装node.js模块?

有很多模块在node的github页面上列出,但是没有用npm-registry发布。 这些模块不能使用npm进行安装。 在从Git中克隆它们之后安装这些nodejs模块的正确方法是什么?

Node.js中path.normalize和path.resolve的区别

path.normalize(your_path)和path.resolve(your_path)之间有什么区别(如果有的path.resolve(your_path) ? 我知道path.resolve(…)可以接受多个参数,但行为与一个单一的参数相同,调用path.normalize() ? 编辑:如果他们应该行为相同的方式,我不明白的目的,揭露path.normalize(…)函数时,你可以简单地将path传递到path.resolve(…)或者,也许, ,这是为了文件的目的。 例如,他们在path.resolve(…)的文档中说: …由此产生的path正常化,并… path.normalize(…)使得更容易解释什么是“规范化”意味着? 我不知道。

发送Content-Type:application / json post与node.js

我们如何在NodeJS中这样做一个HTTP请求? 示例或模块表示赞赏。 curl https://www.googleapis.com/urlshortener/v1/url \ -H 'Content-Type: application/json' \ -d '{"longUrl": "http://www.google.com/"}'

未被捕获的错误:模块没有自注册

我试着用nw.js(v0.12.0-alpha2)来使用node-vlc。 当我启动我的应用程序没有nw.js它的作品,但是当我启动与nw.js我得到一个错误: Uncaught Error:Module did not self-register。“,来源:/home/alexis/Bureau/dev/jukebox/node_modules/vlc/node_modules/ffi/node_modules/bindings/bindings.js(84) 我用nw-gyp尝试了一些命令,但是它不能帮助我。 我在Ubuntu 14,64位。