Gathering detailed insights and metrics for gcp-metadata
Gathering detailed insights and metrics for gcp-metadata
Gathering detailed insights and metrics for gcp-metadata
Gathering detailed insights and metrics for gcp-metadata
Get the metadata from a Google Cloud Platform environment
npm install gcp-metadata
Typescript
Module System
Min. Node Version
Node Version
NPM Version
76.2
Supply Chain
97.4
Quality
90.9
Maintenance
100
Vulnerability
100
License
TypeScript (91.01%)
JavaScript (8.18%)
Python (0.81%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
1,779,258,197
Last Day
639,715
Last Week
13,824,803
Last Month
55,164,743
Last Year
590,854,743
Apache-2.0 License
51 Stars
483 Commits
25 Forks
44 Watchers
86 Branches
123 Contributors
Updated on Feb 11, 2025
Minified
Minified + Gzipped
Latest Version
6.1.1
Package Id
gcp-metadata@6.1.1
Unpacked Size
81.00 kB
Size
22.73 kB
File Count
10
NPM Version
6.14.18
Node Version
14.21.3
Published on
Jan 30, 2025
Cumulative downloads
Total Downloads
Last Day
-4.1%
639,715
Compared to previous day
Last Week
1.3%
13,824,803
Compared to previous week
Last Month
28.8%
55,164,743
Compared to previous month
Last Year
44%
590,854,743
Compared to previous year
Get the metadata from a Google Cloud Platform environment
A comprehensive list of changes in each version may be found in the CHANGELOG.
Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.
Table of contents:
1npm install gcp-metadata
1const gcpMetadata = require('gcp-metadata'); 2 3async function quickstart() { 4 // check to see if this code can access a metadata server 5 const isAvailable = await gcpMetadata.isAvailable(); 6 console.log(`Is available: ${isAvailable}`); 7 8 // Instance and Project level metadata will only be available if 9 // running inside of a Google Cloud compute environment such as 10 // Cloud Functions, App Engine, Kubernetes Engine, or Compute Engine. 11 // To learn more about the differences between instance and project 12 // level metadata, see: 13 // https://cloud.google.com/compute/docs/storing-retrieving-metadata#project-instance-metadata 14 if (isAvailable) { 15 // grab all top level metadata from the service 16 const instanceMetadata = await gcpMetadata.instance(); 17 console.log('Instance metadata:'); 18 console.log(instanceMetadata); 19 20 // get all project level metadata 21 const projectMetadata = await gcpMetadata.project(); 22 console.log('Project metadata:'); 23 console.log(projectMetadata); 24 } 25} 26 27quickstart(); 28
1const isAvailable = await gcpMetadata.isAvailable();
1const data = await gcpMetadata.instance(); 2console.log(data); // ... All metadata properties
1const data = await gcpMetadata.instance('hostname'); 2console.log(data); // ...Instance hostname 3const projectId = await gcpMetadata.project('project-id'); 4console.log(projectId); // ...Project ID of the running instance
1const data = await gcpMetadata.instance('service-accounts/default/email'); 2console.log(data); // ...Email address of the Compute identity service account
1const data = await gcpMetadata.instance({ 2 property: 'tags', 3 params: { alt: 'text' } 4}); 5console.log(data) // ...Tags as newline-delimited list
1await gcpMetadata.instance({ 2 headers: { 'no-trace': '1' } 3}); // ...Request is untraced
In some cases number valued properties returned by the Metadata Service may be
too large to be representable as JavaScript numbers. In such cases we return
those values as BigNumber
objects (from the bignumber.js library). Numbers
that fit within the JavaScript number range will be returned as normal number
values.
1const id = await gcpMetadata.instance('id'); 2console.log(id) // ... BigNumber { s: 1, e: 18, c: [ 45200, 31799277581759 ] } 3console.log(id.toString()) // ... 4520031799277581759
GCE_METADATA_HOST
: provide an alternate host or IP to perform lookup against (useful, for example, you're connecting through a custom proxy server).
For example:
export GCE_METADATA_HOST='169.254.169.254'
DETECT_GCP_RETRIES
: number representing number of retries that should be attempted on metadata lookup.
DEBUG_AUTH
: emit debugging logs
METADATA_SERVER_DETECTION
: configure desired metadata server availability check behavior.
assume-present
: don't try to ping the metadata server, but assume it's presentnone
: don't try to ping the metadata server, but don't try to use it eitherbios-only
: treat the result of a BIOS probe as canonical (don't fall back to pinging)ping-only
: skip the BIOS probe, and go straight to pingingSamples are in the samples/
directory. Each sample's README.md
has instructions for running its sample.
Sample | Source Code | Try it |
---|---|---|
Quickstart | source code | ![]() |
The GCP Metadata Node.js Client API Reference documentation also contains samples.
Our client libraries follow the Node.js release schedule. Libraries are compatible with all current active and maintenance versions of Node.js. If you are using an end-of-life version of Node.js, we recommend that you update as soon as possible to an actively supported LTS version.
Google's client libraries support legacy versions of Node.js runtimes on a best-efforts basis with the following warnings:
Client libraries targeting some end-of-life versions of Node.js are available, and
can be installed through npm dist-tags.
The dist-tags follow the naming convention legacy-(version)
.
For example, npm install gcp-metadata@legacy-8
installs client libraries
for versions compatible with Node.js 8.
This library follows Semantic Versioning.
This library is considered to be stable. The code surface will not change in backwards-incompatible ways unless absolutely necessary (e.g. because of critical security issues) or with an extensive deprecation period. Issues and requests against stable libraries are addressed with the highest priority.
More Information: Google Cloud Platform Launch Stages
Contributions welcome! See the Contributing Guide.
Please note that this README.md
, the samples/README.md
,
and a variety of configuration files in this repository (including .nycrc
and tsconfig.json
)
are generated from a central template. To edit one of these files, make an edit
to its templates in
directory.
Apache Version 2.0
See LICENSE
No vulnerabilities found.
Reason
all changesets reviewed
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
9 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 7
Reason
SAST tool is not run on all commits -- score normalized to 4
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More