How to resolve node pm2 啟動 Error: getaddrinfo ENOTFOUND

#hosts文件中添加
127.0.0.1 localhost
保存,使用命令刷新生效即可。
在新的服務器上部署node以后,使用pm2 作為進程管理工具,

安裝完成以后,pm2 無論執行 

pm2 list 還是pm2 的其它命令,全部報

 Error: getaddrinfo ENOTFOUND

的錯誤。

仔細檢查安裝都沒問題,上git pm2的issue搜索發現,居然是hosts的原因導致的。

默認centos的 hosts 會把本地 127.0.0.1 localhost 注釋掉,去掉再試下就可以了。

參見git pm2 issue:

[https://github.com/Unitech/pm2/issues/324](https://github.com/Unitech/pm2/issues/324) 

原解答:

My fault! My deployment scripts were accidentally deleting the `localhost` from the `/etc/hosts` file, making it impossible to nodejs find the local machine.

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容