Factsheet
» npm install express-generator
» npm install express
» npm install generator-express
» npm install express-generator-typescript
I'm currently doing The Odin Project in which I'm now learning about the Express framework. Multiple sources (The Odin Project, MDN Docs, Express Docs) advise to use the Express Generator to quickly generate a new app skeleton.
However, I have a feeling that this is not the way you do it nowadays. A few reasons why I have that feeling:
The Express Generator Github Repo hasn't been updated for over a year on any branch
When I used it to generate a new app and installed the dependencies, I got a warning saying there are multiple severe vulnerabilities (because of outdated packages?) which I only managed to get rid of by executing
npm audit fix --forcemultiple times, which does not seem to be the way it should be (probably connected to the first reason)The Express Generator package has only about 9000 weekly downloads according to its npm page, while Express itself has almost 30 million weekly downloads
So now I'm wondering if there is an alternative to Express Generator that everybody is using nowadays? Or does everybody just set up everything manually? I couldn't find anything useful regarding that question on the internet. Thanks in advance.
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.
» npm install express-app-generator
» npm install generator-express-crud