How to install modules without npm in node.js ?
Last Updated :
05 Oct, 2021
We can install modules required for a particular project in node.js without npm, the recommended node package manager using yarn. Yarn is a wonderful package manager. Like npm, if you have a project folder with package.json containing all the required dependencies mentioned for the project, you can use yarn to install all the dependencies.
1. How to install yarn?
To install yarn, visit the official installation page of yarn (https://classic.yarnpkg.com/en/docs/install). The page will automatically detect the operating system you are using. Additional installation instructions are also mentioned in the installation page. Once you have followed the steps on the installation manager and the installation process is complete, type the following command in the ternimal/ command prompt.
yarn --version
This should show the particular version you are using in you computer. For example: 1.22.5 . Now that we have installed yarn, lets see how we use yarn in our projects.
2. How to use yarn to install projects?
To use yarn, go to the folder where the modules are needed to be installed. If it is not initialized with yarn, run the yarn init command. It will ask some questions regarding the project to create the package.json file. The package.json file is the most important file as it contains the necessary modules that are required by your project. Anyone with the package.json file, can run some commands( we will discuss this later) to install all the dependencies required by your project. You will get a similar question when you run yarn init command:
question name (testdir): my-awesome-package
question version (1.0.0):
question description:
The best package you will ever find.
question entry point (index.js):
question git repository:
https://github.com/yarnpkg/example-yarn-package
question author: Yarn Contributor
question license (MIT):
question private:
success Saved package.json
Done in 87.70s.
After this is done, a package, json file is created. If you open the package.json file, it should look something like this:
{
"name": "my-awesome-package",
"version": "1.0.0",
"description": "The best package you will ever find.",
"main": "index.js",
"repository": {
"url": "https://github.com/yarnpkg/example-yarn-package",
"type": "git"
},
"author": "Yarn Contributor",
"license": "MIT"
}
Alternatively, if you have a project that contains a package.json file from the beginning, you can use yarn or yarn install command to install all the mentioned dependencies from the package.json file.
Note: If you do not want to answer all the questions when performing yarn init command (although not recommended), you can use yarn init -y command to initialise it with the default values. You can change the details by editing the package.json file with suitable text editor.
3. Installing packages in the project folder
Now we shall see how we can install packages using yarn. Suppose we want to install the package named express. We would enter the following command to install express:
// Command to install express to the current project folder
yarn add express
// Command to install express globally in your machine
yarn global add expres
// This is the most generalized way, Just replace
// the <package-name> with the name of the package
yarn add <package-name>

Note: The global keyword is used to inform yarn that we want to install express globally.
Reference: There are a lot more commands that you can execute with yarn. A list of commands is mentioned in the following link: https://classic.yarnpkg.com/en/docs/cli
If you are migrating from npm to yarn, you can use this cheatsheet to know the similar commands for yarn.
Similar Reads
How to list npm user-installed packages in Node.js?
What is Node.js? Node.js is an open source and cross-platform runtime environment for executing JavaScript code outside of a browser. Click here for more. What is npm? Here, "npm" stands for "Node Package Manager" which is the package manager for Node.js and serves as a command-line utility for inte
2 min read
How to Install Node.js on Windows
Installing Node.js on Windows is a straightforward process, but it's essential to follow the right steps to ensure smooth setup and proper functioning of Node Package Manager (NPM), which is crucial for managing dependencies and packages. This guide will walk you through the official site, NVM, Wind
6 min read
How to Install Node.js and npm on Ubuntu?
If you're developing JavaScript applications on Ubuntu, knowing how to install Node.js on Ubuntu is essential. Node.js is a powerful runtime environment that enables server-side scripting, while npm, the Node Package Manager, allows you to manage your project's dependencies easily. This guide will w
7 min read
How to Install Node.js on Linux
Installing Node.js on a Linux-based operating system can vary slightly depending on your distribution. This guide will walk you through various methods to install Node.js and npm (Node Package Manager) on Linux, whether using Ubuntu, Debian, or other distributions. PrerequisitesA Linux System: such
6 min read
How to work Mongojs module in Node.js ?
Mongojs module is a built-in module in node.js that facilitates the usage of MongoDB with Node.js. It offers almost all the functionality that is provided by the official API of MongoDB and is used extensively by developers across the globe. Follow the steps mentioned below to install mongojs module
3 min read
How To Install A Local Module Using NPM?
To install a local module using npm, it's important to understand how npm (Node Package Manager) works with local packages. npm allows you to manage and install various JavaScript packages and modules, whether theyâre from a remote repository or locally on your system. Installing a local module is p
3 min read
How to Install NodeJS on MacOS?
Node.js is a popular JavaScript runtime used for building server-side applications. Itâs cross-platform and works seamlessly on macOS, Windows, and Linux systems. In this article, we'll guide you through the process of installing Node.js on your macOS system. What is Node.jsNode.js is an open-source
7 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 'Kleur' Module in Node.js ?
'kleur' module is an external NPM module that can manage color properties in JavaScript applications or projects. It allows developers or programmers to manipulate and use colors in their projects. By using kleur, we change the colors of the outputs in the console which make it looks good. Installat
2 min read
How to Install Node & Run npm in VS Code?
Node is an open-source, server-side JavaScript runtime environment built on the V8 engine. It allows developers to execute JavaScript code outside of a web browser, enabling the development of scalable and efficient network applications. Known for its event-driven architecture, NodeJS is widely used
2 min read