当前位置:网站首页>nodejs 简单例子程序之express
nodejs 简单例子程序之express
2022-07-25 18:00:00 【smile_5me】
第一次接触nodejs,只能硬着头皮学习,先不多说,上代码:
const express = require('express')
// 创建服务器
const app = express()
// 监听客户端的请求
// 只有客户端的请求类型是 get,并且 请求地址是 / 根路径的时候,
// 才会调用 后面指定的处理函数
app.get('/', (req, res) => {
// express 中,封装了更好用的 res.send 方法
res.send('你好,express 服务器!')
})
// 监听客户端的post请求,并且请求的地址是 /adduser 的时候,
// 才会调用后面指定的处理函数
app.get('/adduser', (req, res) => {
console.log(req.query);
res.status(200).json({result:"添加成功"});
})
app.post('/',function(req,res){
console.log("主页 POST 请求");
res.send('Hello POST');
})
// 启动服务器
app.listen(4444, () => {
console.log('express server running at http://127.0.0.1:4444')
})这是一个非常简单的服务器,我们打开浏览器,输入:http://127.0.0.1:4444/

那么如果输入http://127.0.0.1:4444/adduser

非常好理解的,看看代码再看看实际演示的效果,其实不难看出,网上有很多很好的例子以及讲解,我这里就不多做解释了,毕竟我也是个新手,还希望有这方面知识的大佬看到这个之后可以给我点意见或者建议。
边栏推荐
- 云VR:虚拟现实专业化的下一步
- PHP解决并发问题的几种实现
- Mock服务moco系列(二)- Json格式、File文件、Header、Cookie、解决中文乱码
- Drawing PDF form (II) drawing excel form style in PDF through iText, setting Chinese font, watermark, logo, header and page number
- Redis source code and design analysis -- 16. AOF persistence mechanism
- OSPF comprehensive experiment
- Postman get started quickly
- Oracle导入出错:IMP-00038: 无法转换为环境字符集句柄
- NPDP多少分通过?如何高分通过?
- Drawing PDF tables (I) drawing excel table styles in PDF and downloading them through iText (supporting Chinese fonts)
猜你喜欢
P2P 之 UDP穿透NAT的原理与实现

Idea integrates common functions of SVN code management

「行话」| 用DevOps高效交付游戏,是种什么体验?

Drawing PDF form (II) drawing excel form style in PDF through iText, setting Chinese font, watermark, logo, header and page number

Redis source code and design analysis -- 15. RDB persistence mechanism

What is an IP SSL certificate and how to apply for it?

Installation and operation instructions of SVN client (TortoiseSVN)

云VR:虚拟现实专业化的下一步

PageHelper还能结合Lambda表达式实现简洁的分页封装

Redis source code and design analysis -- 17. Redis event processing
随机推荐
tkinter GUI版通信录管理系统
go接口变量的类型断言
Cloud VR: the next step of virtual reality specialization
Cloud XR面临的问题以及Cloud XR主要应用场景
云VR:虚拟现实专业化的下一步
Food safety | eight questions and eight answers take you to know crayfish again! This is the right way to eat!
Redistemplate solves the problem of oversold inventory in the seckill system with high speed - redis transaction + optimistic lock mechanism
Memory and packet buffer management of LwIP
越来越成熟的Rust,都应用了哪些场景呢?
SDLC software development life cycle and model
Unity 贝塞尔曲线的创建
How many points did NPDP pass? How to pass with high scores?
PageHelper can also be combined with lambda expressions to achieve concise paging encapsulation
Redis source code and design analysis -- 16. AOF persistence mechanism
Automated test Po design model
WPF implements user avatar selector
Auditing related notes
C LINQ de Duplication & de duplication sum
简述Synchronized以及锁升级
Thesis reading_ Multi task learning_ MMoE