NOTE This project is not at a stable release, it's still in development. Please report any issues you encounter here.
Table of Contents
Please ensure you have Node 14 or above installed on your system. You can check with node --version
. You can use a tool like nvm if you have the incorrect version installed. We recommend Node 16/18.
Run the following command in your project folder to install nitrado.js
npm install nitrado.js
If you are using TypeScript or ESM (import):
import { NitrApi } from 'nitrado.js';
If you are using commonjs (require):
const { NitrApi } = require('nitrado.js');
We recommend storing your API token in a environment variable. The easiest way to do this is by using dotenv. You can however just pass it in as a string.
You can read the guide here on how to get an API token.
-
const api = NitrApi(process.env['NITRADO_TOKEN']);
-
const api = NitrApi('REPLACE_ME');
The api object has a path
function, this is how you can set what path you are making an api request too. Each path might be used for many different requests.
For example lets use the /ping
route.
const api = NitrApi(process.env['NITRADO_TOKEN']);
const ping = api.path('/ping');
When we have the path we can then make a HTTP request to it. For example:
const api = NitrApi(process.env['NITRADO_TOKEN']);
const response = api.path('/ping').get();
response.then((data) => {
console.log(data);
});
Becuase nitrado.js
is fully type safe, intelli-sense will tell you all the possible paths and HTTP methods you can do!
Some paths might have a parameter, for example the following route has the id
parameter: /services/{id}/bouncers
.
We can pass that in along side the path function, as always it's fully typesafe so intellisense will tell you what you need to pass in:
api.path('/services/{id}/bouncers', { id: 'REPLACE_ME' });
On some endpoints we might need to pass in data to the request, for example the bouncers endpoint we saw previously. When we call delete
on it we can pass in some data.
api.path('/services/{id}/bouncers', { id: 'REPLACE_ME' }).delete({
ident: 'REPLACE_ME',
});
When you are logged into the nitrado website, you can visit the following URL to generate your API token. https://server.nitrado.net/eng/developer/tokens
Distributed under the GPL-3.0 License. See LICENSE.txt for more information.