我正在尝试将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"));
};