SHARE
TWEET

Untitled

a guest Oct 19th, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top