-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
55 lines (48 loc) · 1.28 KB
/
app.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
53
54
55
const Hapi = require('hapi');
const mysql = require('mysql');
// server connection();
const server = new Hapi.Server();
//Connecting the server
server.connection({
host: "localhost",
port: 3000,
routes: {
cors: true
}
});
//connect to mysql server
server.app.db = mysql.createConnection({
host: "localhost",
user: "root",
password: '',
database: "ps_gst_billing_task"
});
server.app.db.connect((err) => {
if(err){
console.log("Error while connecting to mysql");
process.exit(1);
}
console.log("Connected to mysql.");
});
const db = server.app.db;
//Load plugins and start server
server.register([
require('./backend/routes/product')
], (err) => {
if (err) {
console.log("Error while loading plugin");
throw err;
}
server.start((err) => {
if (err) {
console.log("Error while strating server");
throw err;
}
console.log(`Server running at: ${server.info.uri}`);
});
});
//Checking if database is working
db.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
if (error) throw error;
console.log('The solution is: ', results[0].solution);
});