🍺Web服务器系列相关文章编写如下🍺:
- 🎈【Web开发】Node.js实现Web服务器(http模块)🎈
- 🎈【Web开发】Node.js实现Web服务器(express模块)🎈
- 🎈【Web开发】Python实现Web服务器(Flask入门)🎈
- 🎈【Web开发】Python实现Web服务器(Flask测试)🎈
- 🎈【Web开发】Python实现Web服务器(Tornado入门)🎈
- 🎈【Web开发】Python实现Web服务器(Tornado+flask+nginx)🎈
- 🎈【Web开发】Python实现Web服务器(FastAPI)🎈
- 🎈【Web开发】Android手机上基于Termux实现Web服务器(Python、node.js)🎈
文章目录
- 1、简介
- 1.1 node.js
- 1.2 express
- 2、安装express库
- 3、代码示例
- 3.1 官方示例1
- 3.2 官方示例2
- 3.3 官方示例3
- 后记
1、简介
1.1 node.js
官网地址:https://nodejs.org/
Node.js 是一个开源和跨平台的 JavaScript 运行时环境。它是几乎任何类型的项目的流行工具!
Node.js 在浏览器之外运行 Google Chrome 的核心 V8 JavaScript 引擎。这使得 Node.js 非常高效。
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiI0gTMx81dsQWZ4lmZf1GLlpXazVmcvwFciV2dsQXYtJ3bm9CX9s2RkBnVHFmb1clWvB3MaVnRtp1XlBXe0xCMy81dvRWYoNHLwEzX5xCMx8FesU2cfdGLwMzX0xiRGZkRGZ0Xy9GbvNGLpZTY1EmMZVDUSFTU4VFRR9Fd4VGdsYTMfVmepNHLrJXYtJXZ0F2dvwVZnFWbp1zczV2YvJHctM3cv1Ce-cmbw5CO4gzN0UWM2YWYwMjY3kjMzYzX2UDNzYTMwIzLclDMyIDMy8CXn9Gbi9CXzV2Zh1WavwVbvNmLvR3YxUjLyM3Lc9CX6MHc0RHaiojIsJye.png)
1.2 express
官网地址:https://www.npmjs.com/package/express Fast, unopinionated, minimalist web framework for node.
2、安装express库
npm install express
or
npm install express --save
or
npm install
3、代码示例
3.1 官方示例1
const express = require('express')
const app = express()
app.get('/', function (req,) {
res.send('Hello World')
})
app.listen(3000)
3.2 官方示例2
Install the executable. The executable’s major version will match Express’s:
npm install
Create the app:
express tmp/foo && cd
Install dependencies:
npm install
Start the server:
npm start
or
node
View the website at: http://localhost:3000
3.3 官方示例3
为了解决fatal: remote error: The unauthenticated git protocol on port 9418 is no longer support。执行如下代码:
git config --global url."https://".insteadOf git://
To view the examples, clone the Express repo and install the dependencies:
git clone git://github.com/expressjs/express.git --depth 1
cd express
npm install
Then run whichever example you want:
node