Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm renewing my discord.js bot folder hirarchy. To make in more structured I made a folder "src" with all js-files. Now if I want to readFileSync a json file outside the src-folder, I can't figure out how to do it.
Lets imagine this Folder:
Folder {
src {
commands {
ping.js
main.js
config1.json
database {
config2.json
I use this command to read a json file:
const config1 = JSON.parse(fs.readFileSync("____config1.json", "utf-8"));
const config2 = JSON.parse(fs.readFileSync("____config2.json", "utf-8"));
I hope my folder illustration was clear. Can someone help me how to access both of those files? The underscores are the missing characters
Thanks in advance!
Just like how you could use cd ..
to navigate back a directory, you can do the same with fs.
const config1 = JSON.parse(fs.readFileSync("../config1.json", "utf-8"));
const config2 = JSON.parse(fs.readFileSync("../database/config2.json", "utf-8"));
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.