我正在使用快递4.0,我知道身体解析器已被取出快递核心,我使用推荐的替代品,但我得到了
body-parser deprecated bodyParser: use individual json/urlencoded middlewares server.js:15:12
body-parser deprecated urlencoded: explicitly specify "extended: true" for extended parsing node_modules/body-parser/index.js:74:29
我在哪里可以找到这个假设的中间件?或者我不应该收到此错误?
var express = require('express');
var server = express();
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var passport = require('./config/passport');
var routes = require('./routes');
mongoose.connect('mongodb://localhost/myapp', function(err) {
if(err) throw err;
});
server.set('view engine', 'jade');
server.set('views', __dirname + '/views');
server.use(bodyParser());
server.use(passport.initialize());
// Application Level Routes
routes(server, passport);
server.use(express.static(__dirname + '/public'));
server.listen(3000);
Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用express和body-parser.
app.use(bodyParser.urlencoded({ extended: false }));
Run Code Online (Sandbox Code Playgroud)
但是,快递4.0中"延伸"的含义是什么?
我找到了这个
extended - parse extended syntax with the qs module.
Run Code Online (Sandbox Code Playgroud)
但是,我仍然无法理解其含义.
有人可以告诉我建议的(最新的)方式来获取明确的POST表格数据.
如此多的教程/帖子等谈论bodyParser,但这不再与Express捆绑,其他博客等建议直接使用urlencoded,但现在这也不可用.
试图找到有关这些框架或技术的准确信息正在努力.
BTW我感兴趣的是非常简单和小型的数据
我正在接收webhook URL上的数据作为POST请求.请注意,此请求的内容类型是application/x-www-form-urlencoded
.
这是服务器到服务器的请求.在我的节点服务器上,我只是试图通过使用读取接收到的数据,req.body.parameters
但结果值是"未定义"?
那么如何读取数据请求数据呢?我需要解析数据吗?我需要安装任何npm模块吗?你能写一个解释案例的代码片段吗?
我正在尝试让一个简单的 MERN 应用程序在 Ubuntu wsl2 实例上运行。我正在遵循本指南。这是我的代码server.js
(它与指南中的代码略有不同,因为 body-parser 已被弃用。使用这篇文章中的建议我已经更改了这些方法)。
const express = require("express");
const mongoose = require("mongoose");
// Setup express app
const app = express();
app.use(
express.urlencoded({
extended: false
})
);
app.use(express.json());
// Configure Mongo
const db = "mongodb://localhost/313-demo-mern-db";
// Connect to Mongo with Mongoose
mongoose
.connect(
db,
{ useNewUrlParser: true }
)
.then(() => console.log("Mongo connected"))
.catch(err => console.log(err));
// Specify the Port where the backend server can be accessed and start listening on …
Run Code Online (Sandbox Code Playgroud) node.js ×5
express ×4
javascript ×2
body-parser ×1
connect ×1
http-post ×1
middleware ×1
mongodb ×1
mongoose ×1