I have been having some problems trying to get my code to work. Everytime I use nodemon to load it, it attempts to connect and gives me a loading icon in the localhost tab. Live-server works when I load the homepage by itself but the index.js won't do the same.
const express = require('express')
const fs = require('fs')
const mysql = require('mysql')
const app = express()
const port = process.env.PORT || 3000
app.use('/public',express.static(__dirname + '/public'))
app.get('/',function(req,res){
fs.createReadStream(__dirname + '/public/HomePage/index.html')
})
const connection = mysql.createConnection({
host: 'localhost',
user:'root',
password:'root',
database:'soorse',
port:8889
})
connection.connect()
const query = connection.query(
SELECT * FROM `users`, function(err,rows,fields){
if(err) throw err;
consol.log(rows)
}
)
app.listen(port)
Instead of doing fs.createReadStream , can you change it to
res.sendFile(__dirname + '/public/HomePage/index.html') ;
Refer to below .
https://expressjs.com/en/api.html#res.sendFileenter link description here