Ask coding questions

← Back to all posts
require() in nodejs not working
SirDerpyHerp (2)

So I tried requiring a file by using the require() function. I have a file named 'db.js' and tried to require it by typing out require("./db.js") but it said "Cannot find module './db.js'

sjatkins (0)

I have the same issue. Something simple like lo = require('lodash') doesn't work anymore. It used to.

timmy_i_chen (1180)

Do you have a repl link we can look at?

timmy_i_chen (1180)

@SirDerpyHerp Ah I think you can only require JS files, so the JSON file would have to be loaded through the fs package or something.