index.js 661 B

12345678910111213141516171819202122232425
  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(express.json())
  9. app.use('/api/authorization',authRouter)
  10. app.use(corsMiddleware)
  11. const start = async() =>{
  12. try{
  13. await mongoose.connect(config.get("mongodb"),{
  14. useNewUrlParser:true,
  15. useUnifiedTopology:true
  16. })
  17. app.listen(PORT,()=>{console.log("server listen:",PORT)})
  18. }catch(e){
  19. console.log("error:",e)
  20. }
  21. }
  22. start()