9 تغريدة 1 قراءة Apr 13, 2023
How to secure your Node.js API key?
Thread 🧵👇
Although making your API key public is a bad idea, it still happens.
- Sometimes, we include it in the GET request parameters.
- Other times, we commit the key to GitHub in our code.
The are two solutions for this.
1️⃣ The first is to implement a proxy for the API.
2️⃣ The second simpler-to-implement solution is to use the .env (environment) file.
Let's demonstrate.
📌 env file
A file containing environment variables is known as an env file.
Variables that are set in the environment in which a program operates are known as environment variables.
They are applied to alter the behavior of the program.
To use env file in Node.js, we need to first install the "dotenv" package.
In the next step, we will import the package in our code.
Now you can access the API key located in the .env file.
Here is an example GET fetch request that includes the API key.
Hope you enjoyed this thread.
If you found this thread useful, follow @Rapid_API 🐙💙

جاري تحميل الاقتراحات...