Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
How to work with secrets in Visual Studio?

In my code, I have API keys and other secrets directly for others to see. I want to prevent that and put them in environment parameter (or hide them otherwise, if you have an idea)

How do I do that? I didn't really understand the answers when I googled it (maybe I looked in the wrong places?)

I would really appreciate the help!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you are using Javascript

1. Add dotenv lib in your project (npm i dotenv or yarn add dotenv)

2. Import to your main file

require('dotenv').config();
or
import 'dotenv/config';

3. Put the variables in a file named ".env" in the root of your project.

Inside this .env file they have to be in the format: KEY=value

...
SECRET=123456abcdef
...

4. Then to use in your project, you can use: process.env.KEY

...
const token = sign({email: user.email},
      process.env.SECRET,
      {subject: user.id, expiresIn: 86400}
    );
...

5. 2. Add .env to .gitignore

//.gitignore
.env
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!