-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (35 loc) · 1.1 KB
/
index.js
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
40
41
const express = require('express')
const app = express()
const dotenv = require('dotenv')
const mongoose = require('mongoose')
const authRoutes = require('./routes/auth')
const userRoutes = require('./routes/user')
const postRoutes = require('./routes/post')
const categoriesRoutes = require('./routes/category')
const multer = require('multer')
dotenv.config();
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
mongoose
.connect(process.env.MONGO_URI)
.then(console.log("connected"))
.catch(err => console.log(err))
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, 'image')
}, filename: (req, file, cb) => {
cb(null, 'image.jpeg')
}
})
//configuration
const upload = multer({ storage: storage });
app.post('/api/upload', upload.single('file'), (req, res) => {
res.status(200).json('file has been uploaded')
})
app.use('/api/auth', authRoutes)
app.use('/api/users', userRoutes)
app.use('/api/posts', postRoutes)
app.use('/api/categories', categoriesRoutes)
app.listen(Port, () => {
console.log("Backend is running..");
})