DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Node.js Microservices Architecture: A Complete Guide
  • Refresh Token Rotation in Node.js: Stopping Token Theft Without Logging Users Out
  • Stop Writing Dialect-Specific SQL: A Unified Query Builder for Node.js
  • Lambda-Driven API Design: Building Composable Node.js Endpoints With Functional Primitives

Trending

  • Giving AI Agents Safe Access to Legacy Systems: Introducing legacy2mcp
  • Why 200 OK Is the Most Dangerous Lie in Enterprise Integration
  • A Walk-Through of the DZone Article Editor
  • The SDLC After AI

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. JavaScript
  4. Making Node.js Available to All Users With nvm

Making Node.js Available to All Users With nvm

When trying to deploy a Node.js application to a remote server, how do we make it so that the user we've created (without sudo privilidges) to run/execute the application can see the necessary libraries needed to run our Node.js application? Read on and find out.

By 
Duncan Brown
·
Apr. 21, 16 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
29.4K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

A not-uncommon situation happens when we try to deploy a Node.js application to a remote server, e.g. via Jenkins:

  1. You set up the remote environment including all libraries needed such as the proper Node version, npm, etc.  This is most likely done under a non-root user with sudo privileges. In this specific scenario, Node is installed via nvm.

  2. You create a user to run/execute the application. This same user is unlikely to be on the sudoers list, and is a user that something like Jenkins can log in as.

  3. You deploy and run your Node application.

Except when you try step 3, you generate an error message, effectively saying that the Node binary cannot be found.

... But we installed it in step 1!

Uh oh.

The first thought is to try installing Node for the user created in step 2. But, that would require giving said user sudo access, which is something you likely do not want to do.

So, how do we get around this? How do we make it so that the user from step 2 can see the necessary libraries needed to run your Node.js application?

There is a way to export the necessary paths for your user.  Have a look at this (at least on Ubuntu):

n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local

Assuming you've kept the nvm and Node.js defaults, this command will put into the appropriate paths for all users the files necessary to run Node in any existing user.

Problem solved!

Have a look at this link for more information on how to set Node up in this kind of situation; indeed, it has additional tips for setting up on a VPS. That same link was also the one that provided that handy bit of code above, so I'm giving credit where it's due—it was a life saver!

Node.js

Opinions expressed by DZone contributors are their own.

Related

  • Node.js Microservices Architecture: A Complete Guide
  • Refresh Token Rotation in Node.js: Stopping Token Theft Without Logging Users Out
  • Stop Writing Dialect-Specific SQL: A Unified Query Builder for Node.js
  • Lambda-Driven API Design: Building Composable Node.js Endpoints With Functional Primitives

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook