Answer the question
In order to leave comments, you need to log in
Trouble deploying node js API to heroku. How to set up correctly?
I'm new to express js
. I'm trying to deploy my project to Heroku
. But due to incorrect database settings, requests get 503
index.js errors.
require('dotenv').config()
const express = require('express')
const sequelize = require('./db')
const models = require('./models/models')
const cors = require('cors')
const fileUpload = require('express-fileupload')
const router = require('./routes/index')
const errorHandler = require('./middleware/ErrorHandlingMiddleware')
const path = require('path')
const PORT = process.env.PORT || 80
const app = express()
app.get('/', (req, res) => {
res.end('<h1>Home</h1>')
})
app.use(cors())
app.use(express.json())
app.use(express.static(path.resolve(__dirname, 'static')))
app.use(fileUpload({}))
app.use('/api', router)
// Обработка ошибок, последний middleware
app.use(errorHandler)
const start = async () => {
try {
await sequelize.authenticate()
await sequelize.sync()
app.listen(PORT, () => console.log(`Server started on port ${PORT}`))
} catch(e) {
console.log(e)
}
}
start()
const {Sequelize} = require('sequelize')
module.exports = new Sequelize(
process.env.DB_NAME,
process.env.DB_USER,
process.env.DB_PASSWORD,
{
dialect: 'postgres',
host: process.env.DB_HOST,
port: process.env.DB_PORT
}
)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question