-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 loc) · 1006 Bytes
/
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
if (process.env.NODE_ENV === 'development'){
require('dotenv').config();
}
const express = require('express');
const morgan = require('morgan');
const multer = require('multer');
const path = require('path');
const cors = require('cors');
// Initializations
const app = express();
require('./database');
// Settings
app.set('port',process.env.PORT||8080);
//Middlewares
app.use(morgan('dev'));
app.use(cors());
const storage = multer.diskStorage({
destination: path.join(__dirname, 'public/uploads'),
filename(req, file, callback){
callback(null,new Date().getTime() + path.extname(file.originalname));
}
})
app.use(multer({storage}).single('image'));
app.use(express.urlencoded({extended:false}));
app.use(express.json());
// Routes
app.use('/api/recipes', require('./routes/recipes'));
/// Static FIles
app.use(express.static(path.join(__dirname,'public')));
// Start the server
app.listen(app.get('port'),() => {
console.log('Server on port', app.get('port'));
})