What is NPM? Why does NPM come with node.js?

What is NPM? Why does NPM come with node.js?

Daily short news for you
  • Manus has officially opened its doors to all users. For those who don't know, this is a reporting tool (making waves) similar to OpenAI's Deep Research. Each day, you get 300 free Credits for research. Each research session consumes Credits depending on the complexity of the request. Oh, and they seem to have a program giving away free Credits. I personally saw 2000 when I logged in.

    I tried it out and compared it with the same command I used before on Deep Research, and the content was completely different. Manus reports more like writing essays compared to OpenAI, which uses bullet points and tables.

    Oh, after signing up, you have to enter your phone number for verification; if there's an error, just wait until the next day and try again.

    » Read more
  • I just found a quite interesting website talking about the memorable milestones in the history of the global Internet: Internet Artifacts

    Just from 1977 - when the Internet was still in the lab - look how much the Internet has developed now 🫣

    » Read more
  • Just thinking that a server "hiding" behind Cloudflare is safe, but that’s not necessarily true; nothing is absolutely safe in this Internet world. I invite you to read the article CloudFlair: Bypassing Cloudflare using Internet-wide scan data to see how the author discovered the IP address of the server that used Cloudflare.

    It's quite impressive, really; no matter what, there will always be those who strive for security and, conversely, those who specialize in exploiting vulnerabilities and... blogging 🤓

    » Read more

When installing node.js, we are "gifted" with npm.

Check the current version of npm.

npm -v
# 6.14.4

NPM, or Node Package Manager, is a repository for open-source node.js projects. It provides solutions to interact with the repository, install packages, manage versions, and manage dependencies through the command line.

Every day, hundreds or thousands of projects are uploaded here, including new libraries or frameworks. This means that most of the things you need are available here.

For example, if you need a library to convert Vietnamese with accents to without accents, instead of writing it yourself, there is already a package called vn-remove-accents available on npm that provides you with that functionality. You just need to install it.

# create a directory
mkdir remove-accents

# move into the directory
cd remove-accents

# install the vn-remove-accents package
npm i vn-remove-accents

Create an index.js file in the remove-accents directory, with the following content:

const removeAccents = require('vn-remove-accents');
const str = 'Blog chia sẻ lập trình kiến thức javascript';
console.log(removeAccents(str)) // Blog chia se lap trinh kien thuc javascript

Most packages on npm come with installation instructions and usage guides, so you don't have to worry too much about how to use them. What you need to do is to identify the package that supports solving your current problem (you can search on Google with your requirements and add "npm" at the end for many suggestions). For example: "vietnam remove accents npm".

Going back to the root remove-accents directory created above, you will see a package.json file is generated, including some information including the vn-remove-accents package that was pulled in, and a node_modules directory.

The node_modules directory will contain the packages that you have installed, such as the vn-remove-accents package mentioned above. The package.json file serves as a dependency management file. When you run npm install, it will install all the packages listed in this file.

NPM is a great tool for node.js, as it saves you from searching for packages from various sources on the internet and eliminates the worry of downloading a project without knowing its dependencies. Everything is covered in the package.json file.

However, not all packages on npm are reliable. Be cautious when installing them.

Premium
Hello

5 profound lessons

Every product comes with stories. The success of others is an inspiration for many to follow. 5 lessons learned have changed me forever. How about you? Click now!

Every product comes with stories. The success of others is an inspiration for many to follow. 5 lessons learned have changed me forever. How about you? Click now!

View all

Subscribe to receive new article notifications

or
* The summary newsletter is sent every 1-2 weeks, cancel anytime.

Comments (1)

Leave a comment...
Avatar
Xuân Hoài Tống4 years ago
npm là một công cụ tuyệt vời cho node.js, nhờ npm ta không phải lang thang trên mạng để tìm những gói từ nhiều nguồn khác nhau, cũng không cần quá lo lắng khi tải một project trên mạng về mà không biết nó dùng những gói phụ thuộc nào. Tất cả đã có file package.json
Reply
Avatar
Xuân Hoài Tống4 years ago
Bạn nói hay quá. Bạn gỡ bình luận đi
Avatar
Hoai Tong Xuan4 years ago
Vẫn là tôi nhưng đến từ Github
Avatar
Gió3 years ago
quay tay à bạn ?