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
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Mastering Node.js: The Ultimate Guide
  • Node.js: Architectural Gems and Best Practices for Developers to Excel
  • Using Render Log Streams to Log to Papertrail
  • How To Use the Node Docker Official Image

Trending

  • The Stairway to Apache Kafka® Tiered Storage
  • Traffic Management and Network Resiliency With Istio Service Mesh
  • Wild West to the Agile Manifesto [Video]
  • Docker and Kubernetes Transforming Modern Deployment
  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.

Duncan Brown user avatar by
Duncan Brown
·
Apr. 21, 16 · Tutorial
Like (2)
Save
Tweet
Share
21.49K 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

  • Mastering Node.js: The Ultimate Guide
  • Node.js: Architectural Gems and Best Practices for Developers to Excel
  • Using Render Log Streams to Log to Papertrail
  • How To Use the Node Docker Official Image

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: