I was build new project with NodeJs. I got this code from youtube channel and its been uploaded 2 years ago. when I trying to practice I got some error. my database cant load and always show "No Comic Here".
this my index.js code:
``` /*
*/
var express = require('express');
var mysql = require('mysql');
//
var connnect=mysql.createConnection
({ host:'localhost',
user:'root',
password:'',
database:'testmanga'
});
//
var app=express();
var publicDir=(__dirname+/'public'/);
app.use(express.static(publicDir));
//
app.get("/banner",(req,res,next)=>{
connnect.query('SELECT * FROM banner',function(error,result,fields){
connnect.on('error',function(err) {
console.log('[MY SQL ERROR]', err);
});
if (result && result.lenght)
{
res.end(JSON.stringify(result));
}
else
{
res.end(JSON.stringify("No Comic Here"));
}
})
});
//
app.get("/comic",(req,res,next)=>{
connnect.query('SELECT * FROM manga',function(error,result,fields){
connnect.on('error',function(err) {
console.log('[MY SQL ERROR]', err);
});
if (result && result.lenght)
{
res.end(JSON.stringify(result));
}
else
{
res.end(JSON.stringify("No Comic Here"));
}
})
});
//
app.listen(3000, ()=>{
console.log("you're connected to port 3000");
})```
I've been trying for changing localhost to 127.0.0.1, but still no working.