Created
October 8, 2021 17:18
-
-
Save gaboluque/1e50648d4c0a855752b50e7549296b39 to your computer and use it in GitHub Desktop.
Simple NodeJS-Express starting file
This file contains hidden or 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
import cors from "cors"; | |
import express, { NextFunction, Request, Response } from "express"; | |
import helmet from "helmet"; | |
import { errorHandler } from "./complements/helpers/errorHandler"; | |
import { userRouter } from "./modules/users/users.router"; | |
// Initial Express configuration | |
const app = express(); | |
app.use(express.json()); | |
app.use(helmet()); | |
app.use(cors()); | |
app.options("*", cors); | |
// Entry point used for health checks or other purposes | |
app.get("/", (_req: Request, res: Response, next: NextFunction) => { | |
res.status(200).json({ success: true }); | |
next(); | |
}); | |
// Users module router | |
app.use("/users", userRouter); | |
// Custom error handler middleware. | |
app.use(errorHandler); | |
// Start server listening | |
app.listen(Number(serverConf.port), "0.0.0.0", (): void => { | |
console.log("Server running on port", serverConf.port); | |
}); | |
export { app }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment