我想在節點上運行簡單的express服務器。但是當我安裝依賴時,它給了我錯誤的節點「無法找到明確」。NodeJS命令「npm install -g」不工作?
這裏是控制檯日誌
[email protected] MINGW64 /f/nitishWorkspace/nitishGitRepo/chatApp (master)
$ npm install -g express
[email protected] C:\Users\asus\AppData\Roaming\npm\node_modules\express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
[email protected] MINGW64 /f/nitishWorkspace/nitishGitRepo/chatApp (master)
$ node server.js
module.js:327
throw err;
^
Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (F:\nitishWorkspace\nitishGitRepo\chatApp\server.js:1:75)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
我認爲問題就出在這些線路
[email protected] C:\Users\asus\AppData\Roaming\npm\node_modules\express
和
[email protected] MINGW64 /f/nitishWorkspace/nitishGitRepo/chatApp (master)
正如你所看到的路徑是不同的在這裏。我認爲依賴關係正在安裝在不同的目錄中,並且節點無法訪問它。 我該如何解決這個問題?
也許會安裝在您的應用程序目錄中。僅當您想從命令行運行全局模塊時才使用全局模塊。所以,只要運行npm我表達,你會很開心。 –