mongoose报错: getaddrinfo ENOTFOUND localhost localhost:27017

{ Error: getaddrinfo ENOTFOUND localhost localhost:27017
    at errnoException (dns.js:50:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'localhost',
  host: 'localhost',
  port: 27017 }
mongoose.connect('mongodb://localhost:27017/db1',{
    poolSize:5,
    useNewUrlParser: true
},err=>{
    if(err){
        console.error(err)
    }else {
        console.log('mongodb 连接成功')
    }
})

将localhost修改为 127.0.0.1 试试

mongoose.connect('mongodb://127.0.0.1:27017/db1',{
    poolSize:5,
    useNewUrlParser: true
},err=>{
    if(err){
        console.error(err)
    }else {
        console.log('mongodb 连接成功')
    }
})
    原文作者:飘啊飘
    原文地址: https://segmentfault.com/a/1190000018880360
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞