1. Install Node.js
It’s been installed for too long, so I don’t write it myself, the link below is very detailed.
Installation Tutorial
2. Install Express
- Open the project folder in VSCode, and then open the terminal;
- Type in the terminal
npm i express
.
In this installation I have the following problems:
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
3.Express use
code show as below:
//1.引入express
const express=require('express');
//2.创建应用对象
const app=express();
//3.创建路由规则
//request是对请求报文的封装
//response是对响应报文的封装
app.get('/',(resquest,response)=>{
response.send('hello');
})
//4.监听端口
app.listen(8000,()=>{
console.log("qidong");
})
VSCode starts the service:
- First open the path in the terminal;
- Type in terminal
node 文件名.js
; - Type it in your browser
127.0.0.1:8000
.