Created
January 26, 2020 00:02
-
-
Save CITGuru/065f31cf4e670b4bbc2bfd0befa2d996 to your computer and use it in GitHub Desktop.
App.js - Live DB
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
const express = require("express"); | |
const cors = require("cors"); | |
require("dotenv").config(); | |
const app = express(); | |
const { LiveDB } = require("./db"); | |
// Middleware | |
app.use(express.json()); | |
app.use(cors()); | |
// Database | |
LiveDB.startDB(); | |
app.get("/", (req, res)=>{ | |
res.send("We are live") | |
}); | |
const PORT = process.env.PORT || 5000; | |
app.listen(PORT, () => { | |
console.log(`Server started on ${PORT}`); | |
}); | |
app.use((err, req, res, next) => { | |
console.log(err); | |
if (err instanceof URIError) { | |
return res.status(400).json({ | |
status: 400, | |
error: `Failed to decode param: ${req.url}` | |
}); | |
} | |
return next(); | |
}); | |
app.use("*", (req, res) => { | |
res.status(404).json({ | |
status: 404, | |
error: "Sorry, we couldn't find that!" | |
}); | |
}); | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment