为什么我无法获取console.log(req.body)?表示,sqlite

时间:2020-05-15 03:18:56

标签: node.js sqlite express

我有问题 问题是我无法获取“ console.log(req.body)”

在我的测试案例中,电子邮件('123@gmail.com')和密码('1234')进入了我的控制器文件夹 我期望一个'req.body.email ='123@gmail.com'','req.body.password ='1234'。 但是,在我的终端中,什么也没有发生! 它不起作用console.log!

我已经安装了“ bodyParser,cors,会话...”,我可以解决的所有问题。 但我没有解决。

下面是我的代码。

((((( in my controller folder ))))
const {user} = require('./models')
module.expots = {
signInController: (req, res) => {
    console.log(req.body)    <<<<<<<<<<<< IT DOES NOT WORKING
}

(((in ./models/user)))
'use strict';
module.exports = (sequelize, DataTypes) => {
  const user = sequelize.define(
    'user',
    {
      email: DataTypes.STRING,
      password: DataTypes.STRING,
      username: DataTypes.STRING,
      mobile: DataTypes.STRING,
    },
    {}
  );
  user.associate = function (models) {
    // associations can be defined here
  };
  return user;
};


(((( index.js ))))
const express = require('express');
const cors = require('cors');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const mysql = require('mysql2');
var bodyParser = require('body-parser');
//
const app = express();
require('./models');

const {
  signInController,
  signUpController,
  userContoroller,
} = require('./controllers');

const port = 4001;
app.use(cookieParser());
app.use(
  cors({
    origin: ['http://localhost:3000'],
    methods: ['GET', 'POST'],
    credentials: true,
  })
);
app.use(
  session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: true,
    cookie: { secure: true },
  })
);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

0 个答案:

没有答案