Overview: How to Manage Node.js Locally

To set up a local development environment on your computer, all you need is to install Node.js. There are, however, some additional things you can do to optimize the way you run Node locally. By the end of this video and written tutorial, you should have a good understanding of how to start developing Node.js apps locally.

In this tutorial we'll:

  • Explain the Node.js release cycle and long term support (LTS) strategy
  • Understand the Node Version Manager and which version(s) of Node.js you should install
  • Work with environment variables in Node.js

Goal

Understand the primary issues around managing a local Node.js installation for development.

Prerequisites

  • None

Watch

Node.js releases and long term support

Node.js never stops getting better. This is great because it means over time it gets easier to use, and we can do more with Node.js. There is a new major release of Node.js on average every 6 months.

But it also means our applications are written aiming at a moving target as new features are added and old ones removed. In order to guarantee that code you write today will continue to function long into the future without the need for constant updates the Node.js community produces regular Long Term Support (LTS) releases.

With LTS you get:

  • Stable interfaces and APIs
  • Security updates
  • Critical bug fixes
  • Some non-breaking new features
  • And most importantly a guarantee that the environment won't change for an extended, period of time

Even numbered releases (10, 12, etc.) enter Active LTS status whenever a proceeding odd numbered release occurs. When this happens the even numbered version enters Active LTS for 18 months. Once the Active LTS period for a version is over it enters Maintenance LTS for 12 months. And then finally, after those 12 months are over it goes to End of Life (EOL) and will no longer be supported.

Diagram of single LTS release lifecycle.Image CC-BY 4.0 by Tierney Cyren / NodeSource

  • Active LTS means that it is being actively maintained and upgraded. This can include backporting new non-breaking features, security updates, bug fixes, etc.
  • Maintenance LTS means the release is nearing EOL and will only receive security updates and bug fixes.

This release cycle means there are multiple LTS versions of Node.js at any given time. Giving developers control over when upgrades happen. If you're shipping an application to production, or embedding your code into an IoT device having a longer cycle with reliable support is good. If you're creating one-off scripts having access to the latest features can be useful.

Diagram of multiple overlapping Node releases charted along a line spanning multiple yearsImage CC-BY 4.0 by Tierney Cyren / NodeSource

You can always find out what the current LTS version is by visiting https://nodejs.org/.

Manage multiple versions with Node Version Manager

Overtime you'll end up working on multiple different Node.js projects each with a different Node.js major version target. The new application you're developing for production might use the latest release, and its new features. While the bugs you need to fix in the code running on an embedded device that shipped a 1.5 years ago is using an older LTS version.

In order to make it easier to work with multiple different versions of Node.js on the same machine we recommend the Node Version Manager, or nvm. Learn more in Install Node.js Locally with nvm.

Manage environment variables

Another common consideration when performing local development is managing environment variables. You'll need a way to make sure that when you are running and debugging that billing application locally you're connected to a test gateway and not the live payment gateway. Or that when testing your email sending service all those test messages don't get sent to real users.

Learn more in Overview: Environment Variables and Setup and Test a .env File.

Recap

At a minimum we recommend installing the current Long Term Support (LTS) version of Node.js. However, choosing a target version for your project depends on your specific use-case. Understanding how the release cycle works can help ensure you make an informed decision. An using tools like nvm can make it easier to manage multiple versions on the same machine.

Further your understanding

  • If you were starting development on a new web application today, with a release goal of 6 months from now, and a development process that made testing and deploying new versions a weekly occurrence which version fo Node.js would you target?
  • How would that change if this was for an embedded system with a more difficult upgrade cycle?

Additional resources

Sign in with your Osio Labs account
to gain instant access to our entire library.

Data Brokering with Node.js