Skip to content

Instantly share code, notes, and snippets.

@Josh4324
Last active July 26, 2021 14:52
Show Gist options
  • Save Josh4324/7bcbc4567c8764c9d607305fc32da8d3 to your computer and use it in GitHub Desktop.
Save Josh4324/7bcbc4567c8764c9d607305fc32da8d3 to your computer and use it in GitHub Desktop.
Initial code inside app.js
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
require("dotenv").config();
const port = process.env.PORT || 3000;
const app = express();
app.use(
express.json({
limit: "10mb",
})
);
app.use(
express.urlencoded({
limit: "10mb",
extended: false,
parameterLimit: 10000,
})
);
//Enable cors
app.use(cors());
app.use(morgan("common"));
app.get("/api", (req, res) => {
const response = new Response(
true,
200,
`Welcome to Sequelize Project ${port}`,
);
res.status(response.code).json(response);
});
//Handling unhandle routes
app.all("*", (req, res, next) => {
const response = new Response(
false,
404,
`Page not found. Can't find ${req.originalUrl} on this server`,
);
return res.status(response.code).json(response);
});
//listening to port
app.listen(port, () => {
console.log(`Welcome to Sequelize Project running on port ${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment