getaddrinfo ENOTFOUND API Google Cloud

北战南征 提交于 2019-12-01 08:19:05

Oh boy, in fact the reason was most stupid ever. I didn't enable "billing" on Google Cloud Platform and that's why it blocked everything (even though I'm using a free test of the API). They just wanted my credit card number. It works now

I had the same issue trying to hit my db. Billing wasn't the fix as I had billing enabled already.

For me it was knexfile.js setup for MySql - specifically the connection object. In that object, you should replace the host key with socketPath; and prepend /cloudsql/ to the value. Here's an example:

connection: {
  // host: process.env.APP_DB_HOST, // The problem
  socketPath: `/cloudsql/${process.env.APP_DB_HOST}`, // The fix
  database: process.env.APP_DB_NAME,
  user: process.env.APP_DB_USR,
  password: process.env.APP_DB_PWD
}

Where process.env.APP_DB_HOST is your Instance connection name.

PS: I imagine that even if you're not using Knex, the host or server parameter of a typical DB connectionstring will have to be called socketPath when connecting to Google Cloud SQL.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!