-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
110 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules | ||
package-lock.json |
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,78 @@ | ||
const express = require("express"); | ||
const app = express(); | ||
const bodyParser = require("body-parser"); | ||
const morgan = require("morgan"); | ||
const mongoose = require("mongoose"); | ||
const cors = require("cors"); | ||
|
||
/** | ||
* Database connectivity | ||
*/ | ||
const localurl = "mongodb://127.0.0.1/moscow" | ||
mongoose | ||
.connect(localurl, { useNewUrlParser: true }, (err, db) =>{ | ||
if(err){ | ||
console.log(err); | ||
console.log("Database Connectivity Error!!"); | ||
} else { | ||
console.log("Database Connectivity Successfull!"); | ||
} | ||
}) | ||
mongoose.Promise = global.Promise; | ||
|
||
|
||
/** | ||
* Using MiddleWares | ||
*/ | ||
app.use(morgan("dev")); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(bodyParser.json()); | ||
// handling cors errors | ||
app.use(cors()); | ||
|
||
|
||
/** | ||
* Routes | ||
*/ | ||
// const rootRoutes = require('./routes/index.js'); | ||
|
||
// app.use('/api', rootRoutes); | ||
|
||
|
||
|
||
|
||
// Handling the errors | ||
/** | ||
* If none of the above middlewares are hit there is definately an error | ||
*/ | ||
app.use((req, res, next) => { | ||
// create a new error object(inbuilt) | ||
const error = new Error("Not Found!!"); | ||
error.status = 404; | ||
// call the universal error handler and pass it to the next middleware this error | ||
// Till here it was sure that a wrong url has been hit. | ||
next(error); | ||
}); | ||
|
||
/** | ||
* Handling universal errors like dberror or server error etc | ||
* we'll have a error function from the previous middleware || from the universal error | ||
* This route is bound to hit | ||
*/ | ||
app.use((error, req, res, next) => { | ||
res.status(error.status || 500); | ||
res.json({ | ||
"error": { | ||
"message": error.message | ||
} | ||
}); | ||
}); | ||
|
||
|
||
|
||
// get the port no. | ||
const port = 5000 || process.env.PORT; | ||
|
||
app.listen(port, "localhost", ()=>{ | ||
console.log("Server running at port " + port); | ||
}); |
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,30 @@ | ||
{ | ||
"name": "hack-moscow", | ||
"version": "1.0.0", | ||
"description": "Our team project for Hack.Moscow", | ||
"main": "index.js", | ||
"scripts": { | ||
"start" : "nodemon index.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Zemotacqy/hack-moscow.git" | ||
}, | ||
"keywords": [ | ||
"Hack.Moscow" | ||
], | ||
"author": "Zemotacqy", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/Zemotacqy/hack-moscow/issues" | ||
}, | ||
"homepage": "https://github.com/Zemotacqy/hack-moscow#readme", | ||
"dependencies": { | ||
"body-parser": "^1.19.0", | ||
"cors": "^2.8.5", | ||
"express": "^4.17.1", | ||
"mongoose": "^5.7.7", | ||
"morgan": "^1.9.1", | ||
"nodemon": "^1.19.4" | ||
} | ||
} |
Empty file.