Using express-generator
express or express-generator: do i need both?
I built an Express app generator which support Typescript, ESM, MVC and more.
A simple boilerplate generator for your node express backend projects.
Looks good. Are middlewares coming soon?
More on reddit.comVideos
» npm install express-generator
» npm install generator-express-crud
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.
Express is a popular web framework for Node.js. However, the official Express generator, express-generator, is starting to show its age. It uses require() modules instead of ESM modules, and it does not support TypeScript.
To address these limitations, I created gen-express-app, a supercharged version of express-generator. gen-express-app uses ESM modules, supports TypeScript, and provides additional features such as routing, templates, and static files.
gen-express-app is easy to use. With a single command, you can generate a complete Express application.
If you are looking for a powerful and easy-to-use Express generator, gen-express-app is the perfect choice.
Here's the link for the github repo: https://github.com/Dalufishe/gen-express-app