NODE.JS installs and uses EXPRESS framework

How to use it (if you need to add a route later, the second method is recommended, otherwise you need to add it manually):
1. Build it yourself

1. Create a new project folder, such as test, and enter the directory in the command line: cd test
2. Initialize npm init, simply use and skip all without configuration (the entry file defaults to index.js)
3. Install express : Npm install express --save
4. Add the following code to the new entry file index.js:

const express = require('express')
const app = express()

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(3000, () => console.log('Example app listening on port 3000!'))

5. Startup: node index.js

6. The browser visits localhost:3000


Second, use the Express application generator express-generator to quickly build

1. Installation: npm install express-generator -g
2. Generate project: express -e project folder name, such as express -e test
3. Enter project folder: cd test
4. Install npm dependent libraries: npm install
5. Start : Npm start
6, the browser visits localhost:3000

Guess you like

Origin blog.csdn.net/youyouxiong/article/details/104616068