Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Working with peer, scoped and private npm dependencies in RHMAP

June 13, 2017
David Martin
Related topics:
Node.js
Related products:
Red Hat build of Node.js

Share:

    RHMAP Environments

    An RHMAP Environment provides a Node.js runtime for Mobile Backends. There are 2 environment types: Dynofarm & OpenShift. The former is an LXC based PaaS, written in Node.js & bash. It is superseded by OpenShift environments. However, there are still many Dynofarm environments in use in the RHMAP SaaS offering.

     

    fh-npm

    Rationale

    fh-npm is a wrapper for npm. It is only used in Dynofarm environments to install npm dependencies specified in a package.json file. It was developed by the RHMAP team to solve a few problems. Older versions of npm were relatively slow at installing dependencies & didn't make great use of the npm cache. Doing a lot of npm installs at the same time can be CPU intensive, so caching pre-built binaries was one of its goals. Also, the amount of disk usage would be relatively high (inodes usage) due to a large number of small files. Some of these problems have been addressed in later versions of npm, and fh-npm is becoming less necessary.
     
    There are features of newer versions of npm that are not supported by fh-npm. This imposes restrictions on what developers can use in their Node.js application. However, it is possible to use these newer features by opting out of fh-npm and triggering the use of an npm version compatible with the version of Node.js being deployed to.

    Opting out of fh-npm

    Adding an npm-shrinkwrap.json file to the root of your application will tell Dynofarm to bypass fh-npm, and use npm instead. This will force you to have your dependencies locked down, as npm will only install the dependencies and versions in your npm-shrinkwrap.json file. The main caveat with doing this is the amount of time to install dependencies, in particular, anything that has to be compiled, as none of the caching that fh-npm providers will be used.
     
    It is possible to bypass fh-npm and not have to maintain an npm-shrinkwrap.json file. This can be useful in the early stages of development where you may not want to lock down versions yet. To do this, add an empty npm-shrinkwrap.json file, and a .npmrc file to the root of your application. Add the following to the .npmrc file.
    shrinkwrap=false
    This combination of files will bypass fh-npm, and tell npm to ignore the npm-shrinkwrap.json file. Only modules in the package.json will be installed.

    Peer Dependencies

    Peer dependencies are not supported by fh-npm. However, if you bypass fh-npm, peer dependencies should work as normal for Node.js 4 environments. Peer dependencies are not supported by the version of npm used in Node.js 0.10 environments. Here is an example of a peer dependency that a grunt plugin might use.
    "peerDependencies": {
      "grunt": ">=0.4.0"
    }

    Scoped & private dependencies

    Scoped dependencies are not supported by fh-npm. However, like peer dependencies, if you bypass fh-npm, scoped dependencies should work as normal. They should work with the version of npm used in Node.js 4 environments, but not 0.10 environments. Here is an example of a scoped dependency.

    "dependencies":{
      "@namespace/mypackage":"~1.0.0"
    }

    The scoped package can be used by required it:

    var mypackage = require("@namespace/mypackage");

    If a scoped module is also private, an extra step is required to allow that module to be downloaded. An authToken of a user that has accessed the private module can be added to the .npmrc file in the root of the repo.

    //registry.npmjs.org/:_authToken=SOME_AUTH_TOKEN

    This token gets used by npm for any private modules in the specified registry. To generate an auth token, login to npm on any machine, then check the ~/.npmrc file for the token line. Tokens can be invalidated by changing your npm password or logging out on the same machine with npm logout.

    Future Node.js versions in Dynofarm

    From Node.js 6.x onwards, fh-npm will no longer be used in Dynofarm. This is due to various changes to npm since version 2, which fh-npm is based on. The layout of the node_modules folder has changed to a flatter structure. This, combined with various performance improvements, has lessened the reasons for fh-npm.


    Red Hat Mobile Application Platform is available for download, and you can read more at Red Hat Mobile Application Platform.

    Last updated: February 23, 2024

    Recent Posts

    • Meet the Red Hat Node.js team at PowerUP 2025

    • How to use pipelines for AI/ML automation at the edge

    • What's new in network observability 1.8

    • LLM Compressor: Optimize LLMs for low-latency deployments

    • How to set up NVIDIA NIM on Red Hat OpenShift AI

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue