-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
40 lines (31 loc) · 1.04 KB
/
server.js
File metadata and controls
40 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import express from "express"
import dotenv from "dotenv"
import bodyParser from "body-parser"
import fileUpload from "express-fileupload"
import path from "path"
import fs, { mkdir } from "fs"
import { fileURLToPath } from 'url';
import { dbConnect } from "./config/db.config.js"
import {userRoute} from "./routes/user.routes.js"
import { videoRoute } from "./routes/video.routes.js"
import { commentRoute } from "./routes/comment.routes.js"
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const tempDir=path.join(__dirname,'tempDir')
if(!fs.existsSync(tempDir)){
fs.mkdir(tempDir,(error)=>console.error(` error in mkdir ${error.message}`))
}
const app=express()
dotenv.config()
app.use(bodyParser.json())
app.use(fileUpload({
useTempFiles:true,
tempFileDir:tempDir
}))
dbConnect()
app.use("/api/user",userRoute)
app.use("/api/video",videoRoute)
app.use("/api/comment",commentRoute)
app.listen(process.env.PORT,()=>{
console.log(`server is running at http://localhost:${process.env.PORT}`)
})