download and use node.js NPM packages

How to Download and use Node.js NPM Packages

 

Let first define a few terms before we go deep into Node.js NPM Packages tutorial.

Define terms

What is NPM?

NPM stands for Node.js Package manager.NPM manages thousands of modules which are hosted in www.npmjs.com. Some packages are free to use while others are restricted.

 Installing Node.js  will automatically install NPM.You can also write your own packages and make them accessible to all developers by packaging them in NPM.

What is a Package?

These are all the files that are needed for a certain module.

What is a Module?

Modules are JavaScript libraries that can be included in a project.

Top 5 most used Node.js NPM Packages.

Do you know that NPM is the world largest software registry with more than 3 billion downloads per week? This tells you how popular is Node.js.NPM contains over 600,000 packages of code blocks. Below are top 5 most used Node.js NPM Packages.

1.express

express.js is a web application server framework that is popular because its fast, robust and focuses on high performance.

2.body-parser

The main use of body-parser is to parse incoming request bodies to middleware before handlers. It’s under req.body property.

Body Parser has the following modules.

  • JSON body parser

  • Raw body parser

  • Text body parser

  • URL-encoded form body parser

3.lodash

Lodash package makes it easier for node.js developers to work with arrays, objects, and strings. Lodash methods can be used in iterating arrays, objects or strings.

4.babel-core

babel-core is popular javascript transpiler. Main use is converting ES6 to ES5, JSX to JavaScript, and Flow to JavaScript.

5.async

async is a module that is used to work with asynchronous JavaScript.It provides powerful and straightforward functions.

Downloading NPM Package.

Here are steps to download and install the NPM Package. First, create a new project by initializing it using “npm init” command. A  package.json file will be created, otherwise, if we try to download the package without JSON file error will pop up.

Create Project

Download upper-case package

output

  • Download upper-case node.js package

A quick look at the project folder.

Node.js project folder

Using Node.js upper-case package

Create an index.js file and use node.js upper-case package. Write below code.

Result.

upper case node.js package

Other cases packages

1.is-upper-case  and is-lower-case

The is-upper-case method is used to check if the string is in upper case format and is-lower-case is used to check if a string is in lower case. The return type of both methods is boolean.

Download is-upper-case and is-lower-case packages in your project. Open visual studio and write below code.

Output

is-lower-case and is-upper-case node.js methods

If we change the var str=“i love programming in node.js” which is a lower case string, below is output.

node.js check if a string is upper case or lower case

2.title-case

Use to convert the first character to upper-case and other characters to lower-case. To install title-case in your project enter

Using title-case

Output

node.js tittle case example
How to use node.js tittle case

3.header-case

Used to header case a string.

Installing header-case

Using

Output

4.lower-case-first.

Used to lowercase the first character in a string.

5.upper-case-first.

Used to uppercase the first character in a string.

6.dot-case.

Used to dot case a string.

Install

Usage

Output

More cases to check out.

That all about  Node.js NPM Packages tutorial.Don’t forget to  share.

Related Node.js Articles.

How to use Node.js Url Module to route application using url.pathname

About the Author: Eric K

Kenyan Developer and Blogger with Interests in Java,Javascript,Node.js, Wordpress, Android, PHP and Making Money Online. Solving world problems through programming is my passion. Hire me: Email : kawi3462@gmail.com