forked from goitacademy/nodejs-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
26 lines (21 loc) · 746 Bytes
/
server.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
import dotenv from 'dotenv';
import mongoose from 'mongoose';
import { app } from './app.js';
import { createFolderIsNotExist } from './handlers/checkFolders.js';
import { storeImage, uploadDir } from './multerConfig/multerConfig.js';
dotenv.config();
const PORT = process.env.PORT || 3000;
const uriDb = process.env.DB_HOST;
const connection = mongoose.connect(uriDb);
connection
.then(() => {
console.log('Database connection successful');
app.listen(PORT, function () {
createFolderIsNotExist(uploadDir);
createFolderIsNotExist(storeImage);
console.log('Server running. Use our API on port: 3000');
});
})
.catch(error => {
console.log(`Server not running. Error message: ${error.message}`);
});