简体   繁体   中英

How to still be able to read files from .gitignore?

Hi I'm trying to create a Discord bot using Discord.js and deploy it to Heroku.

I have successfully deploy it to Heroku, but the logs shows an error. Here is where I think the problem is:

app[worker.1]: Error: Cannot find module './config.json'

config.json cant be found because i put the config.json file inside a .gitignore file. This is because i have some credentials (bot token) that i need to protect inside that file. However, the main file needs access to the config.json in order to run.

Is there any way to still protect the contents of the config.json file while still being able to run the program? The GitHub repository is set to private, so should i exclude config.json from .gitignore instead?

If it's just a small side project, and your GitHub repository is private, there should be no issue in leaving the config.json out of your .gitignore . However, for larger or open-source projects, you can use Heroku's config vars , and that should do the trick. I recommend using config vars but if you just want to throw your code up on Heroku, leaving it out of .gitignore should be fine. I would recommend config vars though, they work reliably.

Thanks, Jackson

You should use environmental variables to save tokens. Then you change your config.json to point to those environmental variables, and not the actual token.

More info on how Heroku does env variables here: https://devcenter.heroku.com/articles/config-vars

(I'm assuming it's not having issues finding your config because it's looking for config.json when the file is actually named config.js or vice versa)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM