Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import express from "express"
  2. import compression from "compression"
  3. import helmet from "helmet"
  4. import morgan from "morgan"
  5. // Add this
  6. import { createConnection } from "typeorm"
  7.  
  8. import config from "./config"
  9.  
  10. const app = express()
  11. // Add middlewares
  12. app.use(express.json())
  13. app.use(express.urlencoded({ extended: false }))
  14. app.use(helmet())
  15. app.use(compression())
  16. app.use(morgan("combined"));
  17.  
  18. (async () => {
  19. try {
  20. const connection = await createConnection()
  21. console.log("Connection to Database established")
  22. } catch(err) {
  23. console.log("DB Connection Error: " + err)
  24. }
  25.  
  26. app.post("*", (req, res) => {
  27. res.status(404).json({
  28. error: true,
  29. message: "Not found"
  30. });
  31. });
  32.  
  33. const port = config.PORT || 3000;
  34.  
  35. app.listen(port, () => {
  36. console.log(`App listening on port ${port}...`)
  37. })
  38. })();
  39.  
  40. export default app
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement