-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (41 loc) · 1.18 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
42
43
44
45
46
47
48
49
50
51
52
//express initialization
const express = require("express");
const app = express();
//dotenv config
require("dotenv").config();
//cors config
var cors = require("cors");
app.use(cors());
//bodyparser configuration
var bodyParser = require("body-parser");
//app.use(bodyParser.json());
app.use(express.json());
// url setup
app.use(express.urlencoded({ extended: true }));
//db setup
const mysql = require("mysql2");
const connection = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
port:process.env.DB_PORT
});
connection.connect();
///////////////MAIN LOGIC
///////////////////HOME
app.get("/", (req, res) => {
res.send(JSON.stringify(process.env.APP_NAME));
});
///////////////////////RECIPES ROUTE
require('./routes/recipes')(app,connection);
///////////////////////INGREDIENTS ROUTE
require('./routes/ingredients')(app,connection);
app.listen(process.env.API_PORT, (error) => {
if (!error)
console.log(
"Server is Successfully Running,and App is listening on port " +
process.env.API_PORT
);
else console.log("Error occurred, server can't start", error);
});