Installing

Caution

Express 5.x is still in beta. Some APIs may change before the final release. Avoid using it in production without first reviewing the migration guide.

Warning

Never commit your node_modules directory to version control. Add it to your .gitignore to prevent accidentally exposing local paths or platform-specific binaries.

Note

By default with npm 5.0+, npm install adds the module to the dependencies list in the package.json file. With earlier versions of npm, you must specify the --save option explicitly. Afterwards, running npm install in the app directory will automatically install all modules in the dependencies list.

Assuming you’ve already installed Node.js, create a directory to hold your application, and make that your working directory.

Terminal window
$ mkdir myapp
$ cd myapp

Use the npm init command to create a package.json file for your application. For more information on how package.json works, see Specifics of npm’s package.json handling.

Terminal window
$ npm init

This command prompts you for a number of things, such as the name and version of your application. For now, you can simply hit RETURN to accept the defaults for most of them, with the following exception:

entry point: (index.js)

Enter app.js, or whatever you want the name of the main file to be. If you want it to be index.js, hit RETURN to accept the suggested default file name.

Now, install Express in the myapp directory and save it in the dependencies list. For example:

Terminal window
$ npm install express

To install Express temporarily and not add it to the dependencies list:

Terminal window
$ npm install express --no-save