简体   繁体   中英

Installation of express in node js

Sir, I am unable to install express in node js using command prompt.

npm install express

在此处输入图片说明

在此处输入图片说明

You have problems with permissions. You have to run as admin if you want to install in that path (Program Files). But you probably don't want to install Express there, but in your application's directory.

Also, there are errors with non existing package.json which you can create running:

npm init

because if you want to install with saving into package.json then you will have to have the package.json first.

Enter your application directory and if there is a package.json run:

npm install express --save

If there is no package.json then run this first:

npm init

and then:

npm install express --save

Make sure that you have write permissions in that directory.

Don't run npm install in your Program Files directory. Instead run it a) in a project directory in c:\\users\\NAME... or b) globally with npm install -g .

I would start with the following steps

1) Create a new folder for your project in your file system somewhere under C:\\users\\NAME...

mkdir PROJECT_NAME
cd PROJECT_NAME

2) In this folder, run npm init to create a new package.json for your project. Follow the wizard in CMD (see https://docs.npmjs.com/cli/init )

npm init

3) Then you can install all the packages you need with npm install (see https://docs.npmjs.com/cli/install ):

npm install --save PACKAGE_NAME
  • Note that npm creates a node_modules/ folder where it stores the packages
  • With the --save argument, npm adds a reference to the package in your package.json file

As @rsp stated already, to perform npm install in *C:\\Program Files*, you would need higher privileges. Running npm as administrator is quit a bad practice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM