File tree Expand file tree Collapse file tree 4 files changed +33
-1
lines changed
Expand file tree Collapse file tree 4 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1+ import config from './config/config'
12import express from 'express'
23import morgan from 'morgan'
4+ import cors from 'cors'
35
46const app = express ( )
57
68//Settings
7- app . set ( 'port' , 3000 )
9+ app . set ( 'port' , config . port )
810
911//Middlewares
12+ app . use ( cors ( ) )
1013app . use ( morgan ( 'dev' ) )
1114app . use ( express . json ( ) )
1215app . use ( express . urlencoded ( { extended : false } ) )
Original file line number Diff line number Diff line change 1+ export default {
2+ port : process . env . PORT || 3000 ,
3+ DB : {
4+ URI : process . env . MONGO_URI || 'mongodb://127.0.0.1:27017/restapijwttspassport_db' ,
5+ USER : process . env . MONGO_USER ,
6+ PASSWORD : process . env . MONGO_PASSWORD
7+ } ,
8+ secretKey : process . env . SECRET_KEY || 'T_LHqi1hEFpsxPZ2heE.wkUKn3k3QSw.DdEK4EQ'
9+ }
Original file line number Diff line number Diff line change 1+ import config from './config/config'
2+ import mongoose from 'mongoose'
3+
4+ mongoose . connect ( config . DB . URI , {
5+ useCreateIndex : true ,
6+ useNewUrlParser : true ,
7+ useUnifiedTopology : true
8+ } )
9+
10+ const connection = mongoose . connection
11+
12+ connection . once ( "open" , ( ) => {
13+ console . log ( "Connection stablished!" )
14+ } )
15+
16+ connection . on ( "error" , ( err ) => {
17+ console . log ( err )
18+ process . exit ( 0 )
19+ } )
Original file line number Diff line number Diff line change 11import app from './app'
2+ import './database'
23
34function main ( ) {
45 app . listen ( app . get ( 'port' ) )
You can’t perform that action at this time.
0 commit comments