Skip to content

Instantly share code, notes, and snippets.

@CITGuru
Created January 26, 2020 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CITGuru/065f31cf4e670b4bbc2bfd0befa2d996 to your computer and use it in GitHub Desktop.
Save CITGuru/065f31cf4e670b4bbc2bfd0befa2d996 to your computer and use it in GitHub Desktop.
App.js - Live DB
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