Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
How to add Dependency in Scala?
Next article icon

How to add a non-npm dependency to package.json?

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

One of the great features of the npm ecosystem is the ability to install and manage packages from the npm registry. These dependencies are listed in the "dependencies" section of the project's package.json file.  However, sometimes you may need to use a dependency that isn't available through npm, such as a library that you've created yourself, or one that hasn't been published to npm yet. In this case, you can add a non-npm dependency to your package.json file. In this article, we'll discuss how to add a non-npm dependency to your package.json file.

Features:

  • Non-npm dependencies can be any library or module that isn't available through npm, such as a local library or a private repository.
  • The process for adding a non-npm dependency to package.json is similar to adding a regular npm dependency.
  • Once added, non-npm dependencies can be imported and used in the same way as regular npm dependencies.

Syntax: To add a non-npm dependency to package.json, you can use the following syntax:

"dependency-name": "file:path/to/dependency"

The "dependency-name" can be any name you choose, and "path/to/dependency" should be the file path to the dependency's source code. This can be either an absolute path or a path relative to the package.json file.

Note: to run the project, remember to type the following in your terminal in order to use the dependencies:

npm install .

There are a few different ways to do this, depending on the type of dependency you are trying to include. Here are the steps for adding each type of non-npm dependency to your package.json file:

Example 1: Git Repositories:  If you want to include a dependency that is hosted in a git repository, you can use the git+ protocol in your package.json file, as shown below: 

"dependencies": {     "my-git-dependency": "git+https://github.com/user/my-git-dependency.git" }

For example, let us create a project that uses the hashmap library on GitHub, which allows one to use any data type as a key for a hashmap object.

package.json

{     "name": "gfg-nj",       "version": "1.0.0",       "description": "",       "main": "index.js",       "scripts": {         "test": "echo \"Error: no test specified\" && exit 1"       },       "dependencies": {            "hashmap" : "https://github.com/flesler/hashmap.git"       },       "author": "",       "license": "ISC" }

index.js: The index.js may be created as follows.

JavaScript
// use the hashmap library added as dependency const HashMap = require('hashmap');  // Creating a new HashMap let map = new HashMap();  // Adding key value pairs map[1] = "one"; map[[2, 3]] = "two"; map[[2, 3]] += "three"; map[3.2] = "three point two";  // Displaying the map console.log(map) 

Output:

 

This will allow you to require the git repository in your project to use the same syntax as any other npm package.

Example 2: Local Files: If you want to use a local file as a dependency in your project, you can add it to your package.json file using the file: protocol. The syntax is provided below:

"dependencies": {      "my-local-dependency": "file:../my-local-dependency" }

This will allow you to require the local file in your project using the following syntax:

const myLocalDependency = require('my-local-dependency');

module.js 

JavaScript
// This file provides a definition for the sum method  function sum(a, b) {     return a + b; } 

To use this file as a dependency, the package.json may be updated to:

{   "name": "gfg-nj",   "version": "1.0.0",   "description": "",   "main": "index.js",   "scripts": {     "test": "echo \"Error: no test specified\" && exit 1"   },   "dependencies": {     "sum-module" : "file:C:\\Users\\phala\\Desktop\\GFG-NJ\\module.js"   },    "author": "",   "license": "ISC" }

To test the module, an index.js file may be created as follows:

JavaScript
// Load the module.js file const sums = require('./module');  // Displaying the result of the sum method console.log(sums.sum(1, 2)); 

Output:

 

Updating Dependencies: Once you have added a non-npm dependency to your package.json file, you can install it using the npm install command. This will download and install the dependency in your project's node_modules directory. If you need to update the dependency to a newer version, you can use the npm update command. This will update the dependency to the latest version specified in your package.json file.

Advantages:

  • Non-npm dependencies can be used in cases where the dependency is not yet or will never be published to npm. This can be useful for projects that use internal or private libraries.
  • It allows one to use a specific version or commit of the dependency, that is not available in npm.

Disadvantages:

  • Non-npm dependencies can be a source of difficulty in the development and maintenance of the project, as they don't follow the same process as npm packages.
  • Managing versions and updates of those dependencies can be harder.
  • It could be harder to find the documentation or support for those dependencies.

Applications:

  • To use internal or private libraries.
  • To use a specific version of a library that is not available on npm.
  • To use libraries that will never be available on npm.
  • Using pre-release versions of packages that are not ready for general consumption.

Adding a non-npm dependency to your package.json file can be a useful way to include libraries or modules that aren't available through npm. While this process is similar to adding regular npm dependencies, it's important to keep in mind that non-npm dependencies can bring additional maintenance and management challenges. Careful consideration should be taken when deciding to use non-npm dependencies in your project, to weigh the advantages and disadvantages. In general, it's best to only use non-npm dependencies when they are necessary, such as in the case of internal or private libraries or to use a specific version of a library not available in npm.


Next Article
How to add Dependency in Scala?

P

phasing17
Improve
Article Tags :
  • Technical Scripter
  • Web Technologies
  • Node.js
  • Technical Scripter 2022
  • JSON

Similar Reads

  • How to update dependency in package.json file ?
    In this article, we will discuss how to update the dependencies of a project with npm. You must have heard about npm which is called a node package manager. So, we can run this command to install an npm package. npm install Note: The --save flag is no longer needed after the Node 5.0.0 version. The
    3 min read
  • How to add Dependency in Scala?
    Scala, a strong language that unites both object-oriented and functional programming techniques has to depend on external libraries to enhance its capabilities. To develop projects seamlessly, there must be efficient handling of these libraries. This is where dependency management becomes important.
    4 min read
  • How To Use Node Modules with npm and package.json
    NodeJS is a powerful runtime for server-side JavaScript & these modules are reusable pieces of code that can be easily imported and used in NodeJS applications. npm (Node Package Manager) is the default package manager for Node JS and is used to install, manage, and publish NodeJS packages. This
    3 min read
  • How to use NPM Trends to Pick a Javascript Dependency?
    Choosing the right JavaScript dependency for your project can be daunting, given the vast number of available packages. npm trends is a valuable tool that helps developers compare the popularity and usage of npm packages over time. By analyzing download statistics, developers can make more informed
    3 min read
  • How to Force an NPM Package to Install?
    Forcing an NPM package to install can be necessary in cases where the dependencies of a package are in conflict or when you need to override existing constraints or force the installation of a specific version. Forcing an NPM package to install refers to using specific commands to bypass version con
    3 min read
  • How to create a REST API using json-server npm package ?
    This article describes how to use the json-server package as a fully working REST API. What is json-server? json-server is an npm(Node Package Manager) module/package, used for creating a REST API effortlessly. Data is communicated in JSON(JavaScript Object Notation) format between client and server
    4 min read
  • How to resolve error "npm WARN package.json: No repository field" ?
    The warning "npm WARN package.json: No repository field" indicates that the package.json file in your project lacks a "repository" field. The "repository" field is crucial for providing information about the version-controlled source code repository of your project. While not mandatory, including th
    3 min read
  • How To Manage Dependencies in Git?
    Managing dependencies is very important for software development, ensuring that your project runs smoothly and is maintainable over time. In Git, managing these dependencies effectively can prevent conflicts, reduce errors, and simplify collaboration within your team. In this article, we'll explore
    6 min read
  • How to Update Local Package in NPM?
    Updating the local packages in NPM is a common task for the developers. Whether it is for bug fixes, new features, or security patches. Keeping your dependencies up to date is essential. These are the following approaches to updating the local package in NPM: Table of Content Update to the Latest St
    4 min read
  • How to document NPM packages ?
    In this article, we will see how to write the documentation of an NPM package. Documentation is an essential part of any NPM package because it gives an idea about the package method and how to use them. Good documentation makes your npm package popular npm packages. The Documentation of the npm pac
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences