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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Stop Writing Dialect-Specific SQL: A Unified Query Builder for Node.js
  • Lambda-Driven API Design: Building Composable Node.js Endpoints With Functional Primitives
  • Integrating Node.js Applications With MCP Servers
  • Unhandled Promise Rejections: The Tiny Mistake That Crashed Our Node.js App

Trending

  • How to Format Articles for DZone
  • Building a DevOps-Ready Internal Developer Platform: A Hands-On Guide to Golden Paths, Self-Service, and Automated Delivery Pipelines
  • Optimizing High-Volume REST APIs Using Redis Caching and Spring Boot (With Load Testing Code)
  • A System Cannot Protect What It Does Not Understand
  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 user avatar
Duncan Brown
·
Apr. 21, 16 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
28.9K Views

Join the DZone community and get the full member experience.

Join For Free

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

  • Stop Writing Dialect-Specific SQL: A Unified Query Builder for Node.js
  • Lambda-Driven API Design: Building Composable Node.js Endpoints With Functional Primitives
  • Integrating Node.js Applications With MCP Servers
  • Unhandled Promise Rejections: The Tiny Mistake That Crashed Our Node.js App

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • 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