express or express-generator: do i need both? express or express-generator: do i need both? express express

express or express-generator: do i need both?


My understanding is:

  • The express package is the framework that exposes functionalities you can use in your code
  • The express-generator package a utility that provides a command-line tool you can use to scaffold your project - ie create boilerplate folder structure, files and code.

As part of the boiler plate files is a package.json file defining the dependencies for your project - ie npm packages that you will need for your project. The express package is listed there.

Knowing the npm install instruction (run with current working directory set to project folder containing the package.json) will "install" all dependencies listed in package.json into your project folder to make them available to your application, it would be sufficient to do:

  • npm install express-generator -g
  • npm install


This answer refers to 'express' v4 on Windows. I don't know what the behavior was with express 3 or less.

0) open a cmd prompt as administrator

1) install express-generator globally;

npm install -g express-generator

2) generate the boilerplate files in your chosen directory, for example

express myApp

3) cd to the myApp folder, where you will find the package.json (+ your main app.js file, + other folders)

4) Finally install 'express' local to your app folder (+ any other dependencies as defined in package.json)

npm install

Notes: the express you are installing in step 4) refers to the set of javascript files which form part of the express web framework, to be used and referenced by your own app; the express referred to in step 2) is actually the express-generator cmd line which you installed globally in step 1).

As for my supplementary question, npm init is used to create a package.json file where you respond to prompts, npm init -y creates the package.json automatically with default values, in either case it is not related to express at all.

If you want to build your project from scratch without boilerplate files / folders, first npm init, then npm install --save express, this installs express locally to your app, the --save option adds express as a dependency in your package.json.

Bottom line, to use the express web framework, you don't have to install express-generator, but you must install express. And if you work on, say, 3 apps which use express, the easiest thing to do is to install express 3 times locally to each app.


You can use both and you won't be able to find any difference between express and express-generator but, many other modules like middleware were not necessary main express so they were added as seperate module and generator is one of those.

This idea of sepearation made express lightweight and manages to generate things efficiently.

In V4, generator is not bindded with express and you need to download two seperate modules.