为什么我不能在node.js中要求express

时间:2012-06-10 03:23:02

标签: node.js express

我正在尝试使用最简单的node.js脚本。这是javascript文件:

server.js

require("express");

我使用regulare node命令启动脚本:

$ node server.js

但是我收到了一个错误:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.
    at Function.<anonymous> (module.js:378:11)
    at Object.<anonymous> (/home/shawn/.node_libraries/express@2.5.9/index.js:4:21)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:32)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/home/shawn/Documents/Projets/passingData/server.js:3:15)
    at Module._compile (module.js:441:26)

发生了什么事?

更新

有趣的是,使用npm install express输出了类似的结果:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.
    at Function.<anonymous> (module.js:378:11)
    at Object.<anonymous> (/home/shawn/.node_libraries/mkdirp@0.3.0/index.js:4:21)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:32)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/usr/lib/nodejs/fstream/lib/dir-reader.js:11:13)
    at Module._compile (module.js:441:26)

1 个答案:

答案 0 :(得分:1)

你需要像这样全局安装它(如果你不把它作为包构建)

npm install express -g

或者如果您在package.json中拥有它,则必须进行本地安装npm install -l,它才能正常运行。