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 连接成功') } })