index.js 685 B

1234567891011121314151617181920212223242526
  1. const express = require("express")
  2. const mongoose = require("mongoose")
  3. const config = require("config")
  4. const authRouter = require("./router/authorization")
  5. const corsMiddleware = require("./middleware/cors")
  6. const PORT = config.get('serverPort')
  7. const app = express()
  8. app.use(corsMiddleware)
  9. app.use(express.json())
  10. app.use('/api/authorization',authRouter)
  11. app.use(corsMiddleware)
  12. const start = async() =>{
  13. try{
  14. await mongoose.connect(config.get("mongodb"),{
  15. useNewUrlParser:true,
  16. useUnifiedTopology:true
  17. })
  18. app.listen(PORT,()=>{console.log("server listen:",PORT)})
  19. }catch(e){
  20. console.log("error:",e)
  21. }
  22. }
  23. start()