Node Modules
- https://www.typescriptlang.org/docs/handbook/module-resolution.html#how-nodejs-resolves-modules (opens in a new tab)
- https://www.typescriptlang.org/docs/handbook/module-resolution.html#node (opens in a new tab)
Module resolution
For bare import (non built-in/relative)
Node.js will start at parent dir of current module, appending /node_modules until root of filesystem reached.
# file path: '/home/ry/projects/foo.js'
require('bar')
# will be resolved with
/home/ry/projects/node_modules/bar.js
/home/ry/projects/node_modules/bar/package.json (if it specifies a "main" property)
/home/ry/projects/node_modules/bar/index.js
/home/ry/node_modules/bar.js
...
/home/node_modules/bar.js
...
/node_modules/bar.js
...(for typescript, replace above .js extensions w/ .ts/.tsx/.d.ts)