【小沐学前端】Node.js实现Web服务器(express模块)

🍺Web服务器系列相关文章编写如下🍺:

  1. 🎈【Web开发】Node.js实现Web服务器(http模块)🎈
  2. 🎈【Web开发】Node.js实现Web服务器(express模块)🎈
  3. 🎈【Web开发】Python实现Web服务器(Flask入门)🎈
  4. 🎈【Web开发】Python实现Web服务器(Flask测试)🎈
  5. 🎈【Web开发】Python实现Web服务器(Tornado入门)🎈
  6. 🎈【Web开发】Python实现Web服务器(Tornado+flask+nginx)🎈
  7. 🎈【Web开发】Python实现Web服务器(FastAPI)🎈
  8. 🎈【Web开发】Android手机上基于Termux实现Web服务器(Python、node.js)🎈

1、简介

1.1 node.js

官网地址:https://nodejs.org/

Node.js 是一个开源和跨平台的 JavaScript 运行时环境。它是几乎任何类型的项目的流行工具!
Node.js 在浏览器之外运行 Google Chrome 的核心 V8 JavaScript 引擎。这使得 Node.js 非常高效。
在这里插入图片描述

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 express -g

在这里插入图片描述

3、代码示例

3.1 官方示例1

const express = require('express')
const app = express()

app.get('/', function (req, res) {
  res.send('Hello World')
})

app.listen(3000)

在这里插入图片描述
在这里插入图片描述

3.2 官方示例2

Install the executable. The executable’s major version will match Express’s:

npm install -g express-generator@4

在这里插入图片描述
Create the app:

express tmp/foo && cd tmp/foo

在这里插入图片描述
Install dependencies:

npm install

在这里插入图片描述
Start the server:

npm start
or
node bin/www

在这里插入图片描述
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 examples/content-negotiation

在这里插入图片描述
在这里插入图片描述

后记

如果你觉得该方法或代码有一点点用处,可以给作者点个赞、赏杯咖啡;╮( ̄▽ ̄)╭
如果你感觉方法或代码不咋地//(ㄒoㄒ)//,就在评论处留言,作者继续改进。o_O???
谢谢各位童鞋们啦( ´ ▽´ )ノ ( ´ ▽´)っ!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值