Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
549 views
in Technique[技术] by (71.8m points)

node.js - 如何跟踪错误“ getaddrinfo ENOTFOUND localhost 3306”(How to trace the error “getaddrinfo ENOTFOUND localhost 3306”)

const express = require('express');
const mysql = require('mysql');
const session = require('express-session');
const path = require('path');
const bodyParser = require('body-parser');

const db = mysql.createConnection({
    host:     "localholst",
    user:     "root",
    password: "password",
    database: "nairobi"
});

db.connect((err) =>{
    if (err) throw err;
    console.log('database connected');
})

const app = express();

app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(express.static('public'));

app.get('/', (req, res) =>{
    res.sendFile(path.join(__dirname + '/index.html'));
});
app.post('/auth', (req, res) =>{
    const username = req.body.username; 
})

app.listen(3000, () =>{
    console.log('Server started on port 3000');
});
  ask by john translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You spelled it wrong.

(您拼写错误。)

const db = mysql.createConnection({
    host:     "localholst",
    user:     "root",
    password: "password",
    database: "nairobi"
});

Change localholst to localhost .

(将localholst更改为localhost 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...