How to get live (spot) gold price using API in Node.js?

< Back to Guides

Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser. To get live gold price using Javascript, we offer three sample code snippets using different method. We offer an offical client library for Node.js. We recommend using the client library. Alternatives includes using the code snippets below using Axios, Native, Request, and Unirest.

For the pure Javascript tutorial, please check out this link.


  1. Get a free API key to use by signing up at and replace REPLACE_ME with your API key.
  2. Update base value to a currency or remove this query param.
  3. Update currencies value to a list of values or remove this query param. In the example below, you will get live precious metal prices for gold, silver, palladium, and platinum.

For 2 and 3, you can find this documented at Offical Documentation


Using Offical MetalpriceAPI library to fetch live gold price in Node.js

See more here GitHub Library

await api.fetchLive('USD', ['XAU', 'XAG', 'XPD', 'XPT']);


Using Axios to fetch live gold price in Node.js

var axios = require('axios');

var config = {
  method: 'get',
  url: ',XAG,EUR',
  headers: { }

.then(function (response) {
.catch(function (error) {


Using Native to fetch live gold price in Node.js

var https = require('follow-redirects').https;
var fs = require('fs');

var options = {
  'method': 'GET',
  'hostname': '',
  'path': '/v1/latest?api_key=REPLACE_ME&base=USD&currencies=XAU,XAG,EUR',
  'headers': {
  'maxRedirects': 20

var req = https.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {

  res.on("end", function (chunk) {
    var body = Buffer.concat(chunks);

  res.on("error", function (error) {



Using Request to fetch live gold price in Node.js

var request = require('request');
var options = {
  'method': 'GET',
  'url': ',XAG,EUR',
  'headers': {
request(options, function (error, response) {
  if (error) throw new Error(error);


Using Unirest to fetch live gold price in Node.js

var unirest = require('unirest');
var req = unirest('GET', ',XAG,EUR')
  .end(function (res) {
    if (res.error) throw new Error(res.error);