-1

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)
michael smith
  • 97
  • 1
  • 1
  • 4
  • The query needs to be surrounded with ***double qoutes or single qoutes*** does not matter which one. see the manual https://github.com/mysqljs/mysql/blob/master/Readme.md#performing-queries .. So i vote close this question because the problem looks to be a simple typographical error – Raymond Nijland Aug 19 '18 at 00:52

1 Answers1

0

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

xan_z
  • 226
  • 1
  • 9