nodejs之express中间件body-parser使用
2024-08-27 14:18:30
1、安装express和body-parser
npm install express
npm install body-parser
2‘、案例如下
var express = require('express');
var bodyParser = require('body-parser')
var app = new express(); app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json()); //引用ejs
app.set('view engine','ejs'); app.get('/',function (req,res) {
res.send("hello express");
}) app.get('/login',function (req,res) {
res.render("login"); }) app.get('/news',function (req,res) {
res.send("hello news1");
}) app.post('/doLogin',function (req,res) {
console.log(req.body);//req.body获取post提交的数据
})
app.listen("");
最新文章
- Resolving SQL Server Disk IO bottlenecks
- html尖角提示框的实现
- 【项目】Http请求在NSMutableURLRequest添加HttpBody的字典params属性
- js反射机制
- BZOJ3888 [Usaco2015 Jan]Stampede
- laravel5.2 移植到新服务器上除了“/”路由 ,其它路由对应的页面显示报404错误(Object not found!)———新装的LAMP没有加载Rewrite模块
- tomcat服务器报Server at localhost was unable to start within 45 seconds的问题
- Git(Repo)常用命令收集
- 关于泛型中<;T extends comparable>;的理解
- #if defined和#if !defined(c语言的宏定义)
- 关于自定义jar包(tomcat)的添加
- 基于STM32的USB枚举过程学习笔记
- R语言︱list用法、批量读取、写出数据时的用法
- vue的ajax请求之axios
- C#模板设计模式使用和学习心得
- Winfrom 动画实现
- hd1007
- svn钩子
- openssl命令实例
- 【转】Braid - 一个发人深思的游戏
热门文章
- 【异常】org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=36, exceptions:
- 2019.9.19HTML基础
- 一般情况下的NB-IoT网络架构
- apache笔记
- 设置ecShop网店用户名和email均可登录
- java代码中的坑
- AT&;T 和 Intel
- 阿里云-docker安装mysql
- hive的外部表
- Unity3D资源