Niansuh commited on
Commit
4261e70
1 Parent(s): ea8123f

Create app.js

Browse files
Files changed (1) hide show
  1. app.js +31 -0
app.js ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const mysql = require('mysql2');
3
+ const apiRoutes = require('./routes/api');
4
+ const app = express();
5
+
6
+ app.use(express.json());
7
+
8
+ // Database connection
9
+ const db = mysql.createConnection({
10
+ host: '31.220.97.62',
11
+ user: 'myapi',
12
+ password: '57rfPPY8bsFBasXX',
13
+ database: 'myapi',
14
+ port: 3306
15
+ });
16
+
17
+ db.connect((err) => {
18
+ if (err) throw err;
19
+ console.log('Connected to MySQL Database');
20
+ });
21
+
22
+ // Set database instance to use in routes
23
+ app.set('db', db);
24
+
25
+ // Routes
26
+ app.use('/api', apiRoutes);
27
+
28
+ const PORT = 3000;
29
+ app.listen(PORT, () => {
30
+ console.log(`Server running on port ${PORT}`);
31
+ });