1.安装Node.js
安装了太久了,就不自己编写了,如下链接很详细。
安装教程
2.安装Express
- 在VSCode中打开项目文件夹,再打开终端;
-
在终端中输入
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启动服务:
- 首先在终端打开该路径;
-
在终端中输入
node 文件名.js
; -
在浏览器中输入
127.0.0.1:8000
。
版权声明:本文为qq_46056318原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。