1# You can run the application generator with the npx command (available in Node.js 8.2.0).
2$ npx express-generator
3# For earlier Node versions, install the application generator as a global npm package and then launch it:
4$ npm install -g express-generator
5# For example, the following creates an Express app named myapp. The app will be created in a folder named myapp in the current working directory and the view engine will be set to Pug:
6$ express --view=pug myapp
7
8 create : myapp
9 create : myapp/package.json
10 create : myapp/app.js
11 create : myapp/public
12 create : myapp/public/javascripts
13 create : myapp/public/images
14 create : myapp/routes
15 create : myapp/routes/index.js
16 create : myapp/routes/users.js
17 create : myapp/public/stylesheets
18 create : myapp/public/stylesheets/style.css
19 create : myapp/views
20 create : myapp/views/index.pug
21 create : myapp/views/layout.pug
22 create : myapp/views/error.pug
23 create : myapp/bin
24 create : myapp/bin/www
25# Then install dependencies:
26$ cd myapp
27npm install
28# On MacOS or Linux, run the app with this command:
29$ DEBUG=myapp:* npm start
30# On Windows Command Prompt, use this command:
31$ set DEBUG=myapp:* & npm start
32# On Windows PowerShell, use this command:
33$env:DEBUG='myapp:*'; npm start
1## Command
2$ npx express-generator
3
4: 'For earlier Node versions, install the application generator as a global
5npm package and then launch it':
6$ npm install -g express-generator
7$ express
8
9## Display the command options with the -h option:
10$ express -h
1# Scaffold an app with Express application generator
2
3# Install express-generator globally by typing the following
4# into a bash terminal (from any directory).
5# open a bash terminal and install globally by typing:
6$ npm install -g express-generator@4.16.1
7
8# Prepend the command with sudo if you are using MacOS or Linux.
9$ sudo npm install -g express-generator
10
11# Note: You may need to close your bash terminal and start a
12# new session before you can use the express command after this installation.
13# First create a main folder for your server
14
15$ mkdir MyNameFolder
16# enter the folder
17$ cd MyNameFolder
18
19# Scaffold out an Express application
20# Here we create a server folder of your own name
21# myservernameServer
22
23# To scaffold out an Express application,
24# type the following at the prompt:
25# view generator now pug as jade is now pug
26
27$ express --view=pug mysitenameServer
28
29# NOTE: If the "express" command does not work for you even after
30# you have installed express-generator globally, you can use command
31
32$ npx express-generator@4.16.1 mysitenameServer
33
34# move into the mysitenameServer folder - type:
35
36$ cd mysitenameServer
37
38# type the following at terminal prompt to install all Node dependencies:
39
40$ npm install
41
42# RUNNING APP
43# MacOS or Linux
44
45$ DEBUG=mysitenameServer:* npm start
46
47# On Windows prompt
48
49$ set DEBUG=mysitenameServer:* & npm start
50
51# Windows PowerShell
52
53$ env:DEBUG='mysitenameServer:*'; npm start
54
55# Then load http://localhost:3000/ in your browser to access the app.
56# The generated app has the following directory structure:
57.
58├── app.js
59├── bin
60│ └── www
61├── package.json
62├── public
63│ ├── images
64│ ├── javascripts
65│ └── stylesheets
66│ └── style.css
67├── routes
68│ ├── index.js
69│ └── users.js
70└── views
71 ├── error.pug
72 ├── index.pug
73 └── layout.pug
74
757 directories, 9 files
76
77