Node's CLI and require()
behave slightly differently:
node path
resolves using path.resolve
- Behaves like you'd expect your operating system to resolve a path.
require(path)
resolves using require.resolve
- The exact behavior is a little complicated, but basically if the beginning of the string looks like a package name, it will look in
node_modules
for a matching package (i.e. doesn't look like a file system path starting with./
,/
,../
, etc).
In your case, you can either install the module with NPM (preferred):
npm install jsdom --save
require("jsdom").jsdom;
Or include the file directly if you've manually added it to your filesystem:
require("./jsdom.js").jsdom;