garyprinting.com

Wave Goodbye to Nodemon: A New Era in Node.js Development

Written on

Chapter 1: A Bright New Start

Greetings, everyone! I'm excited to share some fantastic news that I believe will uplift your spirits.

For those of you in front-end development, here's a game-changer: with the launch of Node.js 18, the reliance on nodemon is about to become a thing of the past. Although I appreciate nodemon for its significant role in boosting my productivity while coding in Node.js, it's time for a farewell.

Why did we ever rely on nodemon? According to nodemon.io, simply use nodemon instead of node to run your applications, and it automatically restarts when your code changes. For instance, if you're crafting a complex utility function, executing nodemon test.js is the way to go instead of node test.js.

Of course, the first step involves installing nodemon, which is quite simple—just run the following command:

npm install -g nodemon

Here's a quick example:

const fn = (name) => {

console.log(name);

}

fn('fatfish');

If I update fn('fatfish') to fn('medium'), nodemon automatically re-runs the code for me. It's such a handy tool—let's raise a glass to nodemon!

Section 1.1: The Shift Away from Nodemon

So, why are we moving on from nodemon?

Well, my friend, by upgrading to Node.js version 18.11.0 or later, you can take advantage of a remarkable new feature. With the command:

node --watch test.js

When I change fn('fatfish') to fn('medium'), Node.js re-executes the code seamlessly, making nodemon redundant.

Subsection 1.1.1: Using Node.js with Watch

While Node.js can effectively replace nodemon, it's essential to append --watch to replicate the same functionality.

Is there a more concise option than typing node --watch test.js? Absolutely!

We can easily streamline this by following two steps:

Step 1: Update Your Shell Configuration

If you're using Bash, run:

vi ~/.bashrc

or

vi ~/.bash_profile

For zsh users, execute:

vi ~/.zshrc

Add the following alias:

alias node="node --watch"

Step 2: Activate the Configuration File

To implement the changes, run:

source ~/.zshrc

Let's give it a try, shall we?

Chapter 2: Embracing the Change

In this video titled "Bye Bye Nodemon!," we delve deeper into the transition away from nodemon and explore the exciting features of Node.js 18.

This second video, "Goodbye nodemon, trying out integrated node watch," showcases practical examples of using the new integrated watch functionality in Node.js.

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

Manifesting Dreams Under the New Moon: 3 Powerful Steps

Discover how to harness the energy of the New Moon for manifestation and rejuvenation with these three effective strategies.

Embrace a Life Beyond the Rush: Finding True Fulfillment

Discover how to escape the relentless hustle and create a fulfilling life focused on meaningful connections and inner peace.

A Path to Improved Health: Embracing the Journey

A reflective account on the journey to better health through exercise, mental well-being, and personal growth.