# Know NPM with Node JS: Install Package, Create Code, Running Code

Assalamualaikum, today we learning about npm (node packege namager) in library node js, go to article…

# 1\. What Is NPM?

* is short, npm is a werehouse or library for extension for developer, or a package for use developer so easy for developing web or aplication, similiar to plugin in figma
    

## 1.1 Type important About NPM:

1. **Dependencies :** the packages must be in developer, bacause its makes process can run and success, like `express`, `sharp`, and any more
    
2. **DevDependencies :** the package not must be in developer, bacause its makes easy when programming in develop our web or aplication, like `eslint`, `nodemon`, and any more
    

# 2\. How Install Package In NPM?

before we install, we are make sure directory appropriate, we are open our terminal (git bash, default terminal, any more), and you can typing this

> **imporatant!!**, bacause in this practic i am use ubuntu, then little different for you user windows, but is ok

## 2.1 Install Package JSON In Directory

this code can create main configurate, like name project, version , and nay more

```bash
--for you whants automatic--
npm init -y

--for you manual creating
npm init
```

after you typing this code, then come a file `package.json` in directory

### 2.1.1 automatic

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757250394510/f62b1180-8f58-4ee4-87ec-cf939bc7ae2b.png align="center")

### 2.1.2 manual

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757250437132/4b84f082-4329-4911-b832-07636b8111e6.png align="center")

## 2.2 Add Type ESM(ECMAScript Module) in package json

After we install package json , we need insert type module for package json, because is important for you use device modern, first you can search in file explorer or you vscode or anything, then insert this code

```bash
"type": "module"
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757251027701/584fec8b-8b9c-48b7-8138-be6631d72ace.png align="center")

## 2.3 Add Code On Object Script

Add this code so that can running your code

```bash
{
  "dev": "node index.js",
  "start": "node main.js",
  "lint": "eslint ."
}
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757252965946/a9e7f0f3-dab2-4f9a-bf16-fc5a5c3a9694.png align="center")

## 2.4 For Exemple Install Package Dependencies

in this exemple we will install package `chalk` for simple input name

```basic
npm install chalk
```

this can make console log very beautiful with add color for your code

this after you download and we will practic it later

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757253315485/bc4cd564-6272-4088-8f1e-228c515ea122.png align="center")

## 2.5 for Exemple Install Package dev Depenidencies

in this exemple we will install sharp for resize image

```bash
npm install sharp --save-optional
```

this after you downloaded, but we don’t will practic because it very complicated

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757252021504/4e21bd59-1f05-4d50-b85e-343e750d0e95.png align="center")

# 3\. Create Code

in this segment we will create code in terminal

```bash
--manual create file
touch name-file.js

--create and edit file
nano name-file.js
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757253452114/437a7107-00bf-4bcc-a581-6e025e379aa4.png align="center")

in this file i try about console anyquestion, and this my code

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757254870813/cf3e052e-d00b-4606-ac38-191d91320d05.png align="center")

after create file input.js, i create file index.js

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757254861790/d823af04-a730-4cfa-81ef-240b8036a322.png align="center")

and i create code again, it’s very bored

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757255652838/ccc3266c-3e1f-4071-b0ff-7c3d2f57b128.png align="center")

# 4\. Running Code

this a code for running we program

```bash
npm run dev
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757256460430/6a981638-24ed-459a-bea4-f76dc5d36c84.png align="center")

# 5\. (Bonus) Practic Use Chalk

in this project i edit file index.js, and use this

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757297005201/5026b7b9-f3a4-4da9-918c-015542c49dc3.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757296986256/db4e6c69-9fb7-4b9e-aff1-1ed224d33038.png align="center")

Boom!!….

# 6\. closing

thanks for your attention, good bye
