nodemon不会加载我的index.js

wkyowqbh  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(322)

我一直有一些问题,试图让我的代码工作。每次我使用nodemon加载它时,它都会尝试连接,并在localhost选项卡中给我一个加载图标。当我自己加载主页时,live服务器可以工作,但是index.js不会这样做。

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)
1tuwyuhd

1tuwyuhd1#

您可以将其改为

res.sendFile(__dirname + '/public/HomePage/index.html') ;

请参阅下文。
https://expressjs.com/en/api.html#res.sendfileenter 此处链接说明

相关问题