Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    JavaScript

    Responsible Web Scraping: Gathering Data Ethically and Legally

    Interview

    Effective Strategies for Acing Part-Time Job Interviews

    Tips

    A Few Productivity Tips and Tools for Web Developers

    Important Pages:
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Today's Picks:
    • Scaling Success: Monitoring Indexation of Programmatic SEO Content
    • Leveraging Influencers: Key Drivers in New Product Launches
    • How Privacy-First Marketing Will Transform the Industry Landscape
    • The Impact of Social Proof on Thought Leadership Marketing
    • Balancing Value-Driven Content and Promotional Messaging Strategies
    • Top Influencer Marketing Platforms to Explore in 2025
    • Emerging Trends in Marketing Automation and AI Tools for 2023
    • Strategies to Mitigate Duplicate Content in Programmatic SEO
    Tuesday, September 9
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Soshace Digital Blog
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Services
    • SaaS & Tech

      Maximizing Efficiency: How SaaS Lowers IT Infrastructure Costs

      August 27, 2025

      Navigating Tomorrow: Innovations Shaping the Future of SaaS

      August 27, 2025

      Maximizing Impact: Strategies for SaaS & Technology Marketing

      August 27, 2025
    • AI & Automation

      Enhancing Customer Feedback Analysis Through AI Innovations

      August 27, 2025

      Navigating the Impact of AI on SEO and Search Rankings

      August 27, 2025

      5 Automation Hacks Every Home Service Business Needs to Know

      May 3, 2025
    • Finance & Fintech

      Critical Missteps in Finance Marketing: What to Avoid

      August 27, 2025

      Analyzing Future Fintech Marketing Trends: Insights Ahead

      August 27, 2025

      Navigating the Complex Landscape of Finance and Fintech Marketing

      August 27, 2025
    • Legal & Compliance

      Exploring Thought Leadership’s Impact on Legal Marketing

      August 27, 2025

      Maximizing LinkedIn: Strategies for Legal and Compliance Marketing

      August 27, 2025

      Why Transparency Matters in Legal Advertising Practices

      August 27, 2025
    • Medical Marketing

      Enhancing Online Reputation Management in Hospitals: A Guide

      August 27, 2025

      Analyzing Emerging Trends in Health and Medical Marketing

      August 27, 2025

      Exploring Innovative Content Ideas for Wellness Blogs and Clinics

      August 27, 2025
    • E-commerce & Retail

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      August 27, 2025

      Emerging Trends in E-commerce and Retail Marketing Strategies

      August 27, 2025

      Maximizing Revenue: The Advantages of Affiliate Marketing for E-Commerce

      August 27, 2025
    • Influencer & Community

      Leveraging Influencers: Key Drivers in New Product Launches

      August 27, 2025

      Top Influencer Marketing Platforms to Explore in 2025

      August 27, 2025

      Key Strategies for Successful Influencer Partnership Negotiations

      August 27, 2025
    • Content & Leadership

      The Impact of Social Proof on Thought Leadership Marketing

      August 27, 2025

      Balancing Value-Driven Content and Promotional Messaging Strategies

      August 27, 2025

      Analyzing Storytelling’s Impact on Content Marketing Effectiveness

      August 27, 2025
    • SEO & Analytics

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      August 27, 2025

      Strategies to Mitigate Duplicate Content in Programmatic SEO

      August 27, 2025

      Effective Data Visualization Techniques for SEO Reporting

      August 27, 2025
    • Marketing Trends

      How Privacy-First Marketing Will Transform the Industry Landscape

      August 27, 2025

      Emerging Trends in Marketing Automation and AI Tools for 2023

      August 27, 2025

      Maximizing ROI: Key Trends in Paid Social Advertising

      August 27, 2025
    Soshace Digital Blog
    Blog / JavaScript / Node.js / Node.js Lessons / Node.js Lesson 3: Node Package Manager
    Beginners

    Node.js Lesson 3: Node Package Manager

    Mohammad Shad MirzaBy Mohammad Shad MirzaSeptember 14, 2020No Comments5 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Node.js Lesson 3: Node Package Manager
    Node.js Lesson 3: Node Package Manager
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    Node.js Lesson 3: Node Package Manager
    Node.js Lesson 3: Node Package Manager

    Hello everyone, we are going to learn about Node Package Manager (NPM) in this lesson. We talked slightly about it in Lesson 1 and initialized the project. Let’s dive deep now.

    What is NPM

    As the name suggests, it’s a Package Manager for Node. Open Source Developers from all around the globe can publish their Node packages and use the packages published by other people for free.

    It is an online repository for the publishing of open-source Nodejs projects.

    It is also a command-line utility to interact with packages in a Nodejs project and manage dependencies. The dependencies are just the packages that are being used in the project. npm cli helps easily install and remove the packages available on the npm registry.

    It helps us rapidly build software with the help of the 1,372k+ packages present on the npm registry. If you’re stuck with a problem, chances are there is already a solution contributed by someone which you can directly.

    NPM comes with standard Node installation. We already have a cli to interact with npm packages. You can check by running npm –version in the terminal. Now let’s understand how it works and how can we create a package ourselves.

    How to create a module and share it with community

    Suppose you have created a package and you want to share it on npm as a package. To keep things basic, let’s consider this is your awesome package:

    // index.js
    module.exports = function(){
        console.log("My awesome module at so share");
    }

    To share this package on NPM, you will have to initialize the repository as an npm package. To do that, you simply have to run one command:

    npm init

    The cli will ask you a bunch of questions regarding package name, version, author, etc and generate a package.json file. It is the same file that is used to track the package version too.

    {
      "name": "supermodule",
      "version": "1.0.0",
      "description": "ERROR: No README data found!",
      "main": "index.js",
      "scripts": {
        "test": "echo "Error: no test specified" && exit 1"
      },
      "author": "Your name here",
      "license": "ISC",
      "repository": ""
    }

    Now we are ready to publish your awesome package.

    Read More:  Create simple POS with React.js, Node.js, and MongoDB #7: Adding redux to other components

    We are naming our package “supermodule”

    How to Publish

    You will need an npm account to publish your package. If you don’t have already, visit the signup page and create an account.

    Once you’re done, open terminal and login with your account using:

    npm login

    You’ll have to enter your username, email, and password to login successfully. Finally, enter this command to publish your package:

    npm publish
    

    Make sure your package name is unique.

    Congratulations, you have published your first package 🎉. You can type npm help to list down all the npm commands.

    How to install a node package

    Now we will talk about how someone can install and use your package in their project. The person simply has to type npm install followed by the package name he wants. For our example, it will be:

    npm install supermodule

    NPM will download the package and save it inside the npm_modules directory. This directory is the default place to save all the installed packages in a project.

    Now the developer doesn’t have to type the full path to the module. NPM checks if the package is present in the node_modules folder and easily imports it into the file:

    import SuperModule = require('supermodule');

    Good job, you have helped someone solve their problem using your awesome package. This is how Open Source Community helps each other and by publishing your package, you have become a part of it 🎉.

    What if the package is no longer needed and you want to uninstall it? You just to type this command in terminal and it will remove your package:

    npm remove "PACKAGE NAME"

    Enter the PACKAGE NAME that you want to remove.

    You can see the meta of the published package by visiting this url:

    http://registry.npmjs.org/supermodule

    Here, you can see all information on the module and its package.json including a link to the module file is contained. This file is also in the database. It was downloaded there automatically in a process of the npm publish command. Note that everything contained in this registry has public access.

    Read More:  16 Best Web Development & Web Design Blogs

    NPM does offer you to publish packages with limited access if you want to limit the usage. It is however paid and you can read more about the pricing on their official page.

    Here, we are providing the path of the module so it’s straight forward. Node will look for the package at the specified location and import it.

    Note: .js is optional. If .js is not present, Node will look either for user.js or user/index.js.

    But what will happen when we don’t provide the path? Example:

    const fs = require('fs');

    At first, Nodejs will see if the required module is a core module. Core modules are modules that are bundled with Nodejs by default. They are present in the /lib directory of your system and takes precedence over everything else. Some of the core modules are fs, https, etc.

    If the module identifier passed to require() is not a core module, and does not begin with ‘/’, ‘../’, or ‘./’, then Nodejs starts at the parent directory of the current module, and adds /node_modules, and attempts to load the module from that location.

    If the package is not found in either of the places mentioned above, Node will start looking for them in global packages. If the NODE_PATHenvironment variable is set to a colon-delimited list of absolute paths, then Node.js will search those paths for modules if they are not found elsewhere.

    Additionally, Node.js will search in the following list of GLOBAL_FOLDERS:

    • $HOME/.node_modules
    • $HOME/.node_libraries
    • $PREFIX/lib/node

    Where $HOME is the user’s home directory, and $PREFIX is the Node.js configured node_prefix.

    That’s it for today’s lesson. We will continue more in Lesson 4.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Mohammad Shad Mirza
    • X (Twitter)
    • LinkedIn

    JavaScript lover working on React Native and committed to simplifying code for beginners. Apart from coding and blogging, I like spending my time sketching or writing with a cup of tea.

    Related Posts

    Mastering REST APIs: Essential Techniques for Programmers

    December 18, 2024

    Crafting Interactive User Interfaces Using JavaScript Techniques

    December 17, 2024

    Effective Strategies for Utilizing Frameworks in Web Development

    December 16, 2024

    Comments are closed.

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo
    Don't Miss
    Beginners May 29, 2019

    Working the Agile Way: Lean and Kanban

    Nowadays, agile is far more than just a number of principles – it incorporates complex methodologies like Lean manufacturing and Kanban. How can they be used to improve your project and make your team more efficient?

    Diam Maecenas Ultricies Mieget Wauris Bibendum Neque

    January 28, 2020

    Уроки React. Урок 4. Домашнее Задание.

    September 14, 2016

    Interview with Ilya

    May 5, 2017

    Categories

    • AI & Automation
    • Angular
    • ASP.NET
    • AWS
    • B2B Leads
    • Beginners
    • Blogs
    • Business Growth
    • Case Studies
    • Comics
    • Consultation
    • Content & Leadership
    • CSS
    • Development
    • Django
    • E-commerce & Retail
    • Entrepreneurs
    • Entrepreneurship
    • Events
    • Express.js
    • Facebook Ads
    • Finance & Fintech
    • Flask
    • Flutter
    • Franchising
    • Funnel Strategy
    • Git
    • GraphQL
    • Home Services Marketing
    • Influencer & Community
    • Interview
    • Java
    • Java Spring
    • JavaScript
    • Job
    • Laravel
    • Lead Generation
    • Legal & Compliance
    • LinkedIn
    • Machine Learning
    • Marketing Trends
    • Medical Marketing
    • MSP Lead Generation
    • MSP Marketing
    • NestJS
    • Next.js
    • Node.js
    • Node.js Lessons
    • Paid Advertising
    • PHP
    • Podcasts
    • POS Tutorial
    • Programming
    • Programming
    • Python
    • React
    • React Lessons
    • React Native
    • React Native Lessons
    • Recruitment
    • Remote Job
    • SaaS & Tech
    • SEO & Analytics
    • Soshace
    • Startups
    • Swarm Intelligence
    • Tips
    • Trends
    • Vue
    • Wiki
    • WordPress
    Top Posts

    10 Practices You Should Avoid to Become a Good Java Developer

    Java May 15, 2023

    Building Mobile Apps With Vue3 and Ionic

    JavaScript November 11, 2020

    Understanding The GIT Workflow

    Git January 27, 2020

    Essential Tips on How to Become a Full Stack Developer

    Programming October 5, 2019

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    About Us
    About Us

    Soshace Digital delivers comprehensive web design and development solutions tailored to your business objectives. Your website will be meticulously designed and developed by our team of seasoned professionals, who combine creative expertise with technical excellence to transform your vision into a high-impact, user-centric digital experience that elevates your brand and drives measurable results.

    7901 4th St N, Suite 28690
    Saint Petersburg, FL 33702-4305
    Phone: 1(877)SOSHACE

    Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
    Our Picks
    Node.js

    How to Upload Images and Videos to Cloudinary in Your Node.js Application: Step-by-Step Tutorial

    React Native

    Build Real-world React Native App #2: React navigation and React native vector icons

    LinkedIn

    Strategies for Identifying High-Quality LinkedIn Prospects by Niche

    Most Popular

    Mastering B2B Lead Generation: A Complete Guide for Success

    B2B Leads

    Automating and Scheduling Tasks Using Python

    Beginners

    23. Node.js Lessons. Domains, asynchronous try.. catch. Part 3.

    Programming
    © 2025 Soshace Digital.
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.