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

3 Answers3

1

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
  • 12,123
  • 3
  • 26
  • 35
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
  • 3,233
  • 2
  • 10
  • 16
0
require('../../command_info.json');
cseitz
  • 1,116
  • 4
  • 16