Last active
June 26, 2020 07:53
-
-
Save kianaditya/cb92e3d225fd0c1540028d4924ff8643 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require('dotenv').config() | |
| const express = require('express') | |
| const logger = require('morgan') | |
| const db = require('./models') | |
| const { createSeeds, deleteSeeds } = require('./models/seeders') | |
| const app = express() | |
| const PORT = process.env.PORT | |
| app.use(logger('dev')) | |
| app.use(express.json()) | |
| app.use(express.urlencoded({ extended: false })) | |
| const postRouter = require('./routes/posts') | |
| app.use('/posts', postRouter) | |
| const seed = process.argv[2] | |
| if (seed) { | |
| db.sequelize | |
| .sync({ force: true }) | |
| .then(() => { | |
| seed === 'create' ? createSeeds() : deleteSeeds() | |
| }) | |
| .catch((err) => { | |
| console.error(err) | |
| }) | |
| } else { | |
| db.sequelize | |
| .sync() | |
| .then(() => { | |
| app.listen(PORT, () => { | |
| console.info(`App listening on port ${PORT}`) | |
| }) | |
| }) | |
| .catch((err) => { | |
| console.error(err) | |
| }) | |
| } | |
| module.exports = app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment