NodeJS команда «НАЯ установка -g» не работает?

Обновить

November 2018

Просмотры

243 раз

1

Я пытаюсь запустить простой экспресс-сервер в узле. Но при установке зависимостей это дает мне ошибку, что узел «Не удается найти экспресс».

здесь консольных журналы

[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)

Как вы можете заметить, путь отличается здесь. Я думаю, что зависимости становятся установить в другой каталог и узел не может получить доступ к этим. Как я могу решить эту проблему ?

Neo

4 ответы

1

Try installing express into your dependencies inside your package.json

npm install --save express

If you do not have a package.json you can create one using the following command from within the root of your project.

npm init -y

This command creates a package.json in your root directory using all the default values.

note

If you use:

npm init

You will be asked a series of questions, but you can set those up later by editing your package.json

See the docs here for more information about package.json

For more information about setting up dependencies see this answer on SO

edit addressing comment

Regarding using globally installed dependencies see this SO q&a

0

So I found the problem: The problem is with the PATH. The node is not able to find this path [email protected] C:\Users\asus\AppData\Roaming\npm\node_modules\express so you can check out this --> answer.

I am not merging the questions because the issue here is different but the solution is same.

Hope this solve the problem.

Neo
0

You probably want to install the ExpressJS CLI generator, if this is the case then run this command

npm install express-generator -g

And then you can type

express my_app

To create a folder with the whole structure inside. Then go inside the created folder:

cd my_app

and type: nam install, to install all the dependencies and express itself.

0

You should install express locally.. do npm install express in your chat app...