whole structure done based on sequelize reccommendation

This commit is contained in:
Arjun Patel
2019-01-04 15:32:36 -08:00
parent 5493c4cef7
commit 2c9aed9952
7 changed files with 112 additions and 40 deletions
+31 -18
View File
@@ -2,29 +2,42 @@
const express = require('express'),
app = express(),
router = express.Router(),
bodyParser = require('body-parser'),
port = process.env.PORT || 4200,
sequelize = require('./sequelize.js');
db = require('./app/config/db.config.js');
app.use(bodyParser.json())
//verify connection to db
db.sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
// force: true will drop the table if it already exists
db.sequelize.sync({force: true}).then(() => {
console.log('Drop and Resync with { force: true }');
});
//define a route, usually this would be a bunch of routes imported from another file
router.get('/', function (req, res, next) {
res.send('Welcome to the Ucharify API');
});
//add routes to express app
// routes(app);
//adding routes to Express app
require('./app/route/donors.route.js')(app);
//start Express server on defined port
app.listen(port);
//log to console to let us know it's working
console.log('Ucharify API server started on: ' + port);
// //verify connection to db
// sequelize
// .authenticate()
// .then(() => {
// console.log('Connection has been established successfully.');
// })
// .catch(err => {
// console.error('Unable to connect to the database:', err);
// });
// Create a Server
var server = app.listen(port, function () {
var host = server.address().address
var port = server.address().port
//server is successful
console.log("App listening at http://%s:%s", host, port)
})