chore: Setup dotenv for the express application

This commit is contained in:
Faruk AYDIN
2021-10-03 20:28:22 +02:00
committed by Ali BARIN
parent fbc2b1e00a
commit a4ddc8b50c
5 changed files with 25 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
import appEnv from './config/app-env'
import createError from 'http-errors';
import express, { Request, Response, NextFunction } from 'express';
import logger from 'morgan';
@@ -5,7 +6,7 @@ import logger from 'morgan';
import indexRouter from './routes/index';
const app = express();
const port = process.env.PORT || '3000';
const port = appEnv.port;
app.use(logger('dev'));
app.use(express.json());
@@ -13,10 +14,6 @@ app.use(express.urlencoded({ extended: false }));
app.use('/', indexRouter);
app.listen(port, () => {
return console.log(`Server is listening on ${port}`)
})
// catch 404 and forward to error handler
app.use(function(req: Request, res: Response, next: NextFunction) {
next(createError(404));
@@ -32,3 +29,7 @@ app.use(function(err: any, req: Request, res: Response, _next: NextFunction) {
res.status(err.status || 500);
res.render('error');
});
app.listen(port, () => {
return console.log(`Server is listening on ${port}`)
})