1

I want to access a json file from the parent directory where the files are set up like this

- files
  - commands
    - admin
      - ban.js <-- the file I want my json in
  - command_info.json

(yes this is for a discord.js bot)

in my ban.js ive used these 4 things:
const {CommandInfo} = require("command_info.json")
const {CommandInfo} = require("./command_info.json")
const {CommandInfo} = require("../command_info.json")
const {CommandInfo} = require(".../command_info.json")
and none of them work as they throw the error: Error: Cannot find module './dev_commands.json'

How would I get my ban.js to include my dev_commands.json

Legacy Coding
  • 544
  • 2
  • 6
  • 30

3 Answers3

2

there is no .... :D So you need to up 2 folders. ../ == up one folder.

const {CommandInfo} = require("../../command_info.json");

Check this out for more information: https://stackoverflow.com/a/23242061/1203844

Aritra Chakraborty
  • 11,235
  • 3
  • 22
  • 32
0

You need to go up 2 times:

const {CommandInfo} = require("../../command_info.json")

Keep in mind each .. means go up once (go to the parent directory).

Amir MB
  • 2,513
  • 8
  • 14
0
require('../../command_info.json');
cseitz
  • 1,026
  • 2
  • 15