Just Scripting the Node
2025-11-28, Fri
This post records notes and thoughts while playing with Node.js.
1. Link Local Module to Global Module
For commonly used frameworks and libraries, it's reasonable to install
them as global package and only link them in project directory. This
could be achieved through the npm link command1. e.g.
take express as example,
npm install -g express cd /path/to/my-project npm link express
The npm link <package-name> command will create a symbolic link
under /path/to/my-project/node_modules to global package.
This command could also be used the other way around: i.e. a symlink created with global prefix2 that points to current project directory. This comes in handy when we want to test a dependent package continuously.
2. Debug Node Applications
If a node application could is run with the --insepct series flags
enabled, then it could be debugged in Chrome like usual web
application through URL chrome://inspect. See the Node documentation
on debugging3 for more info. Some flags are listed
here for reference:
--inspect--inspect-brk--inspect-wait
As for different frameworks, there are usually two approahces:
- Check the script that is actually being run and attach
--inspectflag manually, or - Leverage the flag provided by the framework for debugging.
As for the second approach, take NestJS for example, it provides --debug along with --watch4
for a smooth debugging experience.
Footnotes:
npm-link, with alias ln, refe:
https://docs.npmjs.com/cli/v9/commands/npm-link
Global prefix could be retrieved through npm prefix -g
Node debugging https://nodejs.org/en/learn/getting-started/debugging
NestJS start command options https://docs.nestjs.com/cli/usages#nest-start