connect multiple front end web pages to db code example
Example: create server and connect to db and frontend
'use strict';
const express = require('express');
const app = express();
app.use(express.static('public'));
app.use(express.json());
const mysql = require('mysql');
const con = mysql.createConnection({
host: 'localhost',
user: 'user',
password: 'password',
});
con.connect((err) => {
if(err){
console.log(err.toString());
return;
}
console.log('Connected mysql');
});
app.get('/', (req,res){
res.sendFile('index.html');
});
app.listen(3000);