Nodejs Express框架介绍与使用

1.安装Node.js

安装了太久了,就不自己编写了,如下链接很详细。
安装教程

2.安装Express

  1. 在VSCode中打开项目文件夹,再打开终端;
  2. 在终端中输入npm i express

在这个安装中我出现了如下问题:

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使用

代码如下:

//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启动服务:

  1. 首先在终端打开该路径;
  2. 在终端中输入node 文件名.js
  3. 在浏览器中输入127.0.0.1:8000
    在这里插入图片描述
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_46056318/article/details/127394169