A Deep Dive into use Node js third-party Packages


What is a Package?

A package in Node.js contains all the files you need for a module.

Modules are JavaScript libraries you can include in your project.

Download a Package

Downloading a package is very easy.

Open the command line interface and tell NPM to download the package you want.

I want to download a package called follow-redirects:

npm i follow-redirects

Test the Package On Runkit

var followRedirects = require("follow-redirects")
const { http, https } = require('follow-redirects');
 
http.get('http://bit.ly/900913', response => {
  response.on('data', chunk => {
    console.log(chunk);
  });
}).on('error', err => {
  console.error(err);
});

RunKit notebooks completely remove the friction of trying new ideas. With one click you’ll have a sandboxed

JavaScript environment where you can instantly switch node versions, use every npm module without having to wait to install it, and even visualize your results. No more configuration, just straight to coding.

Something Else Important Maybe You need

Find and automatically fix open source vulnerabilities

Use the Snyk Online tools you can get the Package Health Score.

Let get the follow-redirects’s Health Score:

Follow-redirects's vulnerabilities

You can get more detail info about package follow-redirects’s vulnerabilities on the Snyk page.

Modify the third-party package’s Code and use it directly

  1. Fork the code to you github
  2. Change the code and push it to you github
  3. Use this commond npm install [your github name]/[package name] in your project

For example, My GitHub is earthandy and I want to use hexo-generator-amp which I forked from tea3, just use:

npm install earthandy/hexo-generator-amp --save

Author: Andy Zhang
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Andy Zhang !
评论
 Previous
Experience the MQTT protocol of IOT Experience the MQTT protocol of IOT
The MQTT (MQ Telemetry Transport) protocol is a lightweight network protocol developed by IBM in 1999. It adopts a publish-subscribe communication model.
2022-02-18
Next 
Flutter Challenge the Twitter App Flutter Challenge the Twitter App
Flutter Challenges will attempt to recreate a particular app UI or design in Flutter.This challenge will attempt the home screen of the Twitter Android app. Note that the focus will be on the UI rather than actually fetching data from a backend server.
2022-01-29
  TOC