- yarn init
- In package.json, add:
"scripts": {
"server": "nodemon index.js"
}
- yarn add nodemon express helmet knex sqlite3 cors bcryptjs express-session connect-session-knex jsonwebtoken
- npx knex init
- Update knexfile.js -- filename: location and name of your database, migrations and seeds locations:
module.exports = {
development: {
client: 'sqlite3',
useNullAsDefault: true,
connection: {
filename: './database/auth.db3',
},
pool: {
afterCreate: (conn, done) => {
conn.run('PRAGMA foreign_keys = ON', done);
},
},
migrations: {
directory: './database/migrations',
},
seeds: {
directory: './database/seeds',
},
},
};
- Create index.js file:
const server = require('./api/server.js');
const port = process.env.PORT || 5000;
server.listen(port, () => console.log(`\n** Running on port ${port} **\n`));
- npx knex migrate:make create_x_table -- to create your tables
- Go into migrations and work on each of the tables
- npx knex migrate:latest
- npx knex seed:make 001-dishes -- to create seeds if needed
- npx knex seed:run
- Create dbConfig.js in database folder
const knex = require('knex');
const config = require('../knexfile.js');
const environment = process.env.DB_ENV || "development";
module.exports = knex(config[environment]);
- Create x-model.js in x folder
- Create auth folder