Created
October 1, 2021 05:22
-
-
Save ats1999/688607e9b626be2f567635b2e1434b24 to your computer and use it in GitHub Desktop.
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
require("dotenv").config(); | |
const express = require("express"); | |
const bodyParser = require("body-parser"); | |
const cookieParser = require("cookie-parser"); | |
const cors = require("cors"); | |
const morgan = require("morgan"); | |
// middleware | |
const authMiddleware = require("./middleware/auth"); | |
// apis | |
const auth = require("./routes/auth/auth"); | |
const user = require("./routes/user/user"); | |
const test = require("./routes/test"); | |
// connect Db | |
require("./config/db"); | |
// express | |
const app = express(); | |
const PORT = process.env.PORT || 5005; | |
//app.set('view engine', 'ejs') | |
app.use(cors({ origin: true, credentials: true })); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: false })); | |
app.use(cookieParser()); | |
app.use(morgan(":method :url :status - :response-time ms")); | |
// apis | |
app.use("/api", auth); | |
app.use("/api/test", test); | |
app.use("/api/user",user); | |
app.get("/", (_, res) => res.send("Server is working...")); | |
// unwanted route | |
app.use((req, res, next) => { | |
const error = new Error("Route not found!"); | |
error.status = 404; | |
next(error); | |
}); | |
// error handling function | |
app.use(function (error, req, res, next) { | |
if (!error.status && !error.msg) console.log(error); | |
const status = error.status || 500; | |
res.status(status).send(error); | |
}); | |
app.listen(PORT, () => console.log(`Server is running on ${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
{ | |
"name": "components-server", | |
"version": "1.0.0", | |
"description": "Server made to used for components", | |
"main": "index.js", | |
"engines": { | |
"node": "12.x" | |
}, | |
"scripts": { | |
"start": "node index.js", | |
"dev": "nodemon index.js" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "git+https://github.com/ats1999/components-server.git" | |
}, | |
"author": "Rahul (github.com/ats1999)", | |
"license": "MIT", | |
"bugs": { | |
"url": "https://github.com/ats1999/components-server/issues" | |
}, | |
"homepage": "https://github.com/ats1999/components-server#readme", | |
"dependencies": { | |
"@sendgrid/mail": "^7.4.7", | |
"bcrypt": "^5.0.1", | |
"body-parser": "^1.19.0", | |
"cookie-parser": "^1.4.5", | |
"cors": "^2.8.5", | |
"dotenv": "^10.0.0", | |
"express": "^4.17.1", | |
"jsonwebtoken": "^8.5.1", | |
"mongoose": "^6.0.7", | |
"morgan": "^1.10.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment