Introduction and use of Nodejs Express framework

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

  1. Open the project folder in VSCode, and then open the terminal;
  2. 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.

Solution

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:

  1. First open the path in the terminal;
  2. Type in terminal node 文件名.js;
  3. Type it in your browser 127.0.0.1:8000.
    insert image description here
    insert image description here

Guess you like

Origin blog.csdn.net/qq_46056318/article/details/127394169