-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BE #1: Bootstrap the project using express.
Create Config folder where all configs are declare. Use consola to log in the console. Use mongoose to connect with the mongoDB.
- Loading branch information
Atiqul Alam Rocky
committed
May 11, 2020
1 parent
4d61305
commit 6d8d0dc
Showing
4 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,5 @@ cache_temp/* | |
static_temp/* | ||
.vscode | ||
notice-config.js | ||
package-lock.json | ||
package-lock.json | ||
.env |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,62 @@ | ||
const express = require('express'); | ||
const logger = require('morgan'); | ||
const fs = require('fs') | ||
const { connect } = require('mongoose') | ||
const {success, error, info, log} = require('consola'); | ||
|
||
//Bring the app constants | ||
const {DB, PORT} = require('./config/application'); | ||
|
||
//Initialize the application | ||
const app = express(); | ||
|
||
let retryAttemptCount = 5; | ||
const startApp = async function(){ | ||
try{ | ||
//DB connection | ||
info({ | ||
message:'Trying to connect to the Database....', | ||
badge:true | ||
}) | ||
|
||
await connect(DB, { | ||
useUnifiedTopology: true, | ||
useNewUrlParser: true, | ||
useFindAndModify: true | ||
}) | ||
|
||
info({ | ||
message:`Successfully conneted to the Database \n${DB}`, | ||
badge: true | ||
}); | ||
|
||
//Start to listen the port | ||
app.listen(PORT, () => { | ||
log({ | ||
message:`Server started and listening on PORT: ${PORT}`, | ||
badge:true | ||
}) | ||
}); | ||
|
||
}catch(err){ | ||
error({ | ||
message:`Unable to connect to Database /n${DB}\n${err}` | ||
}); | ||
|
||
while(retryAttemptCount > 0){ | ||
--retryAttemptCount; | ||
startApp(); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
startApp() | ||
|
||
|
||
app.get('/', (req, res) => { | ||
res.send('Hello CMS!') | ||
}); | ||
|
||
app.listen(3000, () => { | ||
console.log('Server started and listening on PORT: 3000'); | ||
}); | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require('dotenv').config(); | ||
|
||
module.exports = { | ||
DB: process.env.APP_DB, | ||
PORT: process.env.PORT || 3000 | ||
} |
This file contains 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