I have been trying to move some variables to an external file so I decided to create a config.json
{
"username":"...",
"password":"...",
"identity_secret":"...",
"shared_secret":"...",
"hostname":"127.0.0.1",
"owner":"..."
}
And then require it as a module
'use strict'
var ACCEPT = 0xf
var REPORT = 0xff
var DECLINE = 0xfff
var fs = require('fs')
var config = require('./config.json')
But whenever I run the script I constantly get this error
module.js:457
throw err;
^
Error: Cannot find module 'config.json'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/root/steam-bot/steam_bot.js:8:14)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
I'm on node v6.4.0
with node bot.js
This is a single file script so I couldn't have had the chance to change the loading directory and both files are indeed in the same directory
It seems the import isn't throwing the error as this script works
var fs = require('fs')
var config = require('./config.json')
console.log(config.username)