📜  我需要在 middelware 中使用 node.js 添加内容类型接受表单数据 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:33.098000             🧑  作者: Mango

代码示例1
var express = require('express');
var app = express();
var multer = require('multer');
var upload = multer();

// for parsing application/json
app.use(express.json()); 

// for parsing application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: true })); 

// for parsing multipart/form-data
app.use(upload.array()); 
app.use(express.static('public'));

app.post('/api/user', function (req, res) {
    console.log(req.body);
    console.log(req.body.username);
});

module.exports = app;