找不到express.js导出模块

时间:2019-06-04 07:42:29

标签: node.js express model-view-controller

我正在尝试将sekultse放在一个单独的文件中。

const Sequelize = require("sequelize");

const sequelize = new Sequelize({
    username: 'yourname',
    password: 'yourname',
    database: 'test',
    dialect: "test",
    host: "localhost",
    port: "5432"
});

const User = sequelize.define("User", {
    id: {
        type: Sequelize.INTEGER,
        autoIncrement: true,
        primaryKey: true,
        allowNull: false
    },
    name: {
        type: Sequelize.STRING,
        allowNull: true
    },
});

module.exports = User;

但是当我尝试在控制器中使用此波特时,找不到它。

const User = require('../models/user.js');

   exports.index=function(req, res) {   
   sequelize.sync().then(result => {
   });
   User.findAll({raw: true}).then(data => {
        res.json(data)
   }).catch(err => console.log("error"));

     };

文件结构: enter image description here

0 个答案:

没有答案