Find the host’s cloud provider using Node.Js

If you ever wanted to inject or use cloud provider-specific code in the codebase or DevOps work, You can now do it very easily thanks to cloud-detect-js(https://github.com/vithalreddy/cloud-detect-js#readme) Node.js Module, which helps to determine host machine’s cloud provider using machine’s file system and metadata.

Detect Host’s Cloud Provider

This Module Provides a very simple API as follows:

const { cloudProvider } = require('cloud-detect-js');

(async () => {
  await cloudProvider();
  // wil return one of  'aws', 'gcp', 'azure', 'oracle', 'alibaba', 'do' or 'unknown'
})();

It also has an cli version

Via NPM:

npm install -g cloud-detect-js
Via Yarn:

yarn add global cloud-detect-js

Usage: cloud-detect-js [options] [command]

Options:
  -V, --version  output the version number
  -h, --help     output usage information

Commands:
  detect|d       Detect's Host Machine's Cloud Provider

cloud-detect-js d
# aws

cloud-detect-js detect
# gcp

It can also be downloaded from NPM @ https://www.npmjs.com/package/cloud-detect-js

See also  Get User's IP address in Node.js (Express.js)

Leave a Comment