2012-06-10 57 views
0

我試圖獲得最簡單的node.js腳本來運行。這裏是JavaScript文件:爲什麼我不需要在node.js中快速運行

server.js

require("express"); 

我使用regulare節點命令啓動腳本:

$ 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/[email protected]/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) 

發生了什麼事?

UPDATE

有趣的是,使用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/[email protected]/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

你已經完成'npm install express'了嗎? – sntran

+0

'npm install express'也會導致錯誤,請參閱我的編輯。 – Shawn

+3

看起來像你有老npm。嘗試將node.js和npm更新爲當前的穩定版本。 –

回答

1

需要在全局安裝它像這樣(如果你不把它建設成爲包)

npm install express -g 

或者如果你有它在package.json你必須做本地安裝npm install -l,它會正常工作。

+0

你可以省略「-l」。只需創建一個'package.json'並執行'npm install'。 – TheHippo

相關問題