The use of Express is performed on a Node basis. So you need to install Node first. Go to CMD and check to see if node is already installed on your computer. Enter the command node -v in CMDCopy the code

After installing Node as shown above, you will be shown the version you installed. If no installation is available, go to the node official website :nodejs.org/zh-cn/ and select an appropriate installation.

After the installation, go to CMD to check whether there is a version to confirm that it is installed. The next step:

Create a new express.js file and open it in the terminal: initialize first --> command: NPM init --yes Install express--> command: NPM I expressCopy the code

//1. Express const {response} = require("express"); const express=require("express"); const { request } = require("http"); Const app=express() //3. App.get ("/",(request,response)=>{// Set the response body response.send("Hello ") Express") }) //4. Listen (8000,()=>{console.log(" server started ")})Copy the code

After the above code is written, run the command node.express.js in its terminal (enter the command node ex and press TAB to auto-complete) to start the server. Next, enter the local IP address 127.0.0.1:8000 in the browser to access the response body of our own simulated Settings.

We talked about the server on, so how to turn it off?

Just press CTRL + CT to shut down the server, which needs to be shut down and restarted every time the express.js file is modified. Some people will say there is no convenient, modify the file after only need to save his automatic restart? The answer is yes!

On the express.js terminal, run the NPM i-g nodemon commandCopy the code

After running the above command, restart the server again (run the command: nodemon.express.js), you can see the following picture, I did not press CTRL + C, as long as the save will automatically restart the server.