[JavaScript] Cfx.re API Library (FiveM/RedM)

Presentation


Hello ! I created a npm package to interact with the Cfx.re API and fetching some data from it and the status page.

Here are some of the things you can do :

  • Retrieving a FiveM/RedM server data:
    • Hostname
    • Connected players
    • Active resources
    • Public variables (tags, oneSync enabled etc.)
    • Owner data (id, cfx username, avatar)
    • Upvote power
    • … And much more !
  • Retrieving Cfx.re services status from the status page:
    • Check if all services are ok
    • Check every components individually

This project will be maintained and I will update it as I am able to add new features.
JavaScript developers are welcome to contribute to the project and improve it and/or add new features!

Download / Using


The project is available on GitHub: GitHub - PABLO-1610/cfx-api: JavaScript library to interact with the Cfx.re API (FiveM/RedM)

Or if you just want to add it to an existing node project:
npm i cfx-api

Usage example


const cfx = require("cfx-api");

(async () => {
  // Retrieve a CitizenFX server (could be a FiveM or a RedM server)
  const server = await cfx.fetchServer("qrbm5v") // Replace "qrpm7v" with a server id
  console.log(`Server: ${server.hostname} has ${server.players.length} players online`);

  // Retrieve Cfx.re status
  const status = await cfx.fetchStatus()
  console.log(status.everythingOk ? "All Cfx.re systems are operational" : "Cfx.re is experiencing issues");

  // And get status of all individual components
  const components = await status.fetchComponents()
  for (let component of components) {
    console.log(`${component.name}: ${component.status}`);
  }
})();

Some projets to do with


Here some ideas:

  • Discord bot to retrieve server data
  • Fetching a server to display its logo on a website
  • A status alert when FiveM is encountering an issue

Thanks :slight_smile:

14 Likes

Hey nice repo ! How to find the id of my localhost for some test ? Or localhost have no id ?

1 Like

Good work!

1 Like

You find your ID by going to the keymaster website (https://keymaster.fivem.net)
image

1 Like

Yep, thanks for replying.

And sv_lan has to not be set to 1

Is there any documentation on the possible values that can be received? I’m interested, about the other values that can be returned for component.status other than operational.

I will write a documentation in the week in the “Wiki” page of the GitHub repo

Where exactly do i find the doc? Can’t seem to find the wiki section