You give the function in b.js the __dirname in a.js. Example:
a.js:
const b = require("../lib/b.js"); b.someFn(__dirname);