Member-only story
Three Hidden but Very Useful Features of Node.js
In day-to-day Node.js development, we often encounter problems that require frequent service restarts, manual loading of environment variables, and a desire to output more intuitively. These problems are small, but they have a huge impact on development efficiency and experience.
The article I shared today can solve the above problems very well, let’s take a look at three hidden but very useful features of the Node.js to make our development process more smooth and efficient.
- Code changes are automatically reloaded
Node.js has added an experimental feature since the fall of 2022 that allows Node.js to automatically restart code when a filesystem change is detected via the --watch command-line flag. This eliminates the need for me to use an external tool like nodemon to monitor file changes. For example, run the following command:
node --watch watch1.js
The content of the watch1.js is very simple:
console.log('Watch me!', new Date());
When the script is run, if the script is modified, Node.js will automatically restart the script and clear the entire terminal screen with a useful restart and completion message.