-1

So ive made a discord bot, and in it, i have the token separate from the main file so i can hide it from github. I use vs code to make changes, but when i commit and push them, it pushes the file i want hidden too. Is there a way I can tell vs code to not push the hidden file so i can keep it secret?

I have const token = require('./config.json'); to import the token, and i could keep it in a different folder than vs code opens, but I would like to avoid that. I have tried adding it to the .gitignore and deleting it from the repo, but when i pull in vs code it deletes the local file. I don't think i fully understand the gitignore file though.

johng3587
  • 103
  • 9
  • Try to use Node environment variables. https://stackoverflow.com/questions/22312671/setting-environment-variables-for-node-to-retrieve You could also look into [dotenv](https://www.npmjs.com/package/dotenv) – Zsolt Meszaros Feb 09 '21 at 21:22

1 Answers1

4

Use a .gitignore file. Adding an entry to your gitignore file makes git ignore that file/folder entirely, making sure that it does not get committed. You will continue to see it in VS code, but it will not get committed anymore. I would consider regenerating your bot token since the previous commits with your config.json will still be publicly accessible on GitHub. Learn more...

  • Ok, thank you! The repository is currently private so no-one can see the token, but I was going to make it public once i had got this figured out. – johng3587 Feb 09 '21 at 21:31