Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS Google Vision is unable to detect a Project Id in the current environment

Under Ubuntu environment, NodeJS Google Vision complains:

Error: Unable to detect a Project Id in the current environment.

Even though I already put json credential through

$ export GOOGLE_APPLICATION_CREDENTIALS=/var/credential_google.json"

Please help.

like image 622
Arif Chasan Avatar asked Jun 14 '19 12:06

Arif Chasan


People also ask

Why can't I detect a project ID in the current environment?

If you get the error "Unable to detect a Project Id in the current environment.", it means the auth library cannot find the project default id. You need to have a base project in Google Cloud set, regardless of environmental variables and project you're running. It will load the project environment.

How to find Google project ID?

How to Find Google Project ID 1 Go to the API Console. 2 From the projects list, select Manage all projects. The names and IDs for all the projects you're a member of are displayed. See More....

How to deploy a project in Google Cloud?

You need to have a base project in Google Cloud set, regardless of environmental variables and project you're running. It will load the project environment. This also allows you to deploy easier with: App engine has security setup automatically with standard environments. With flex you can use one of the manage images Google Provides.

How do I identify my project?

There are two ways to identify your project: the project name and project ID. You create the project name when you create the project. The project ID is a unique identifier for a project and is used only within the console. When you first create a project, you can accept the default generated project ID or create your own.


Video Answer


1 Answers

It's not recommended to use a .json config file locally. I've seen these leak on production servers causing whole platforms to be deleted + the introduce environmental switching and security issues.

Setup Google Cloud CLI.

Now the server will 'look' at the local environment and use that.

If you get the error "Unable to detect a Project Id in the current environment.", it means the auth library cannot find the project default id.

You need to have a base project in Google Cloud set, regardless of environmental variables and project you're running.

Run

gcloud config set project [some-project-id]

Now if you run (node example)

"dev": "NODE_ENV=dev GCP_PROJECT=some-project-id nodemon index.ts",

It will load the project environment. This also allows you to deploy easier with:

"deploy:dev": "y | gcloud app deploy --project some-dev-project app.yaml",
"deploy:prod": "y | gcloud app deploy --project some-prod-project app.yaml"

App engine has security setup automatically with standard environments. With flex you can use one of the manage images Google Provides.

like image 126
Oliver Dixon Avatar answered Jan 03 '23 23:01

Oliver Dixon