Skip to content

What is Express Generator?

Express Generator is a tool that quickly sets up a boilerplate Express.js application. It saves time by generating a pre-configured project structure, allowing you to focus on building your app instead of setting up the basics.

Command to Use Express Generator

Run the following command to create a new Express project:

Terminal window
npx express-generator my-app
  • npx: Runs the express-generator package without globally installing it.
  • my-app: The name of your new project folder.

You can also specify additional options like a view engine:

Terminal window
npx express-generator --view=pug my-app

Steps After Running the Command

1.Navigate to Your Project:

Terminal window
cd my-app

2.Install Dependencies: Install the required packages listed in package.json:

Terminal window
npm install

3.Run the Server: Start the application:

Terminal window
npm start

By default, the server will run at http://localhost:3000.

Key Features

  • Preconfigured Setup: Comes with a basic folder structure for routes, views, and public files.
  • Static File Serving: public/ folder is used for static assets like CSS and JavaScript.
  • Middleware: Includes middleware like morgan for logging.
  • View Engine Support: Choose a template engine (pug, ejs, etc.) during setup using the —view option.