Skip to main content

Storing your credentials

Now you have your credentials, where are you going to put them?

It's best practice to not keep your credentials in your main script since if you want to publish it or accidentally send a screenshot of it, anybody now has access to them!

There are a few ways to store your credentials, but the way we'll be storing them is by making a config.json file.

Making the file

First, make a new config.json file in the same path as your main script. Now, put in your credentials like this:

config.json
{
"serverKey": "SERVER-KEY-HERE",
"authorizationKey": "AUTHORIZATION-KEY-HERE" // If you don't have an authorization key, remove this line.
}

Make sure to replace SERVER-KEY-HERE with your actual server key, and AUTHORIZATION-KEY-HERE with your actual authorization key if you have one.

Accessing the credentials in your main script

To now access this file in your main script, you can just use the built-in require() function. Here's how:

main.js
const { serverKey, authorizationKey } = require("./config.json") // './' means 'in this directory'

You can now access your credentials with serverKey and authorizationKey in your main script.