Express insert values into MySQL database

江枫思渺然 提交于 2019-12-06 04:51:03

If I understand correctly the directory structure of your project, you have the routes directory next to the models directory, right? if this is the case, you need to change the require in routes/index.js to use ../, so it will get to the right location:

var User = require('../models/User');

Problem solved when I change db.js. The key is the module.exports = db; part, I guess.

var knex = require('knex')({
    client: 'mysql',
    connection: {
        host     : 'localhost',
        user     : 'root',
        password : 'root',
        port    : 8889,
        database : 'bosluk',
        charset  : 'utf8'
    }
});

var db = require('bookshelf')(knex);

module.exports = db;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!