index.js 755 B

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