Node.js Express framework learning
Reprint and reference address:
https://developer.mozilla.org/zh-CN/docs/Learn/Server-side/Express_Nodejs/development_environment
https://developer.mozilla.org/zh-CN/docs/Learn/Server-side/Express_Nodejs/skeleton_website
1. Create a folder
2. Under the cmd command, enter the current folder
3. Initialize the npm environment (otherwise direct download module will report an error)
npm init -y
4. Install the express module, generator generator
npm install express npm install -g express-generator
5. Enter the application directory and run the following command to create an Express application named "helloworld":
express helloworld
If no project name is specified, the express application will be generated in the current directory by default. The following screenshot is this usage.
=======================================================================
After creating the express application, the system prompts::
\ 006_Project__nodejs \ Demo2> express --view = pug
destination is not empty, continue? [Y / N] y
create : public\
create : public\javascripts\
create : public\images\
create : public\stylesheets\
create : public\stylesheets\style.css
create : routes\
create : routes\index.js
create : routes\users.js
create : views\
create : views\error.pug
create : views\index.pug
create : views\layout.pug
create : app.js
create : package.json
create : bin\
create : bin\www
install dependencies:
> npm install
run the app:
> SET DEBUG = demo2: * & npm start
The commands on the bottom 2 lines are very important! ! ! ! !
================================================== =====================
6. Use the following command to install all dependencies for the helloworld application:
cd helloworld npm install
7. Then run this application (Windows environment):
> SET DEBUG=helloworld:* & npm start
(Linux / macOS environment):
$ DEBUG=helloworld:* npm start
8. Open the browser and visit http://127.0.0.1:3000/ You will see the default welcome page of Express.