The NPM(Node Package Manager) Universe

NPM: node package manager

1. A library of thousands of packages published by other developers that we can use for free

2. A command line tool to easily install and manage those packages in out node projects

examples: Jokes and Color

https://www.npmjs.com/package/give-me-a-joke

https://www.npmjs.com/package/colors

Step 1: install packages:

npm i give-me-a-joke

npm i colors

Step 2: require package name

Step 3: call functions accroding to particular API

//index.js
const jokes = require("give-me-a-joke"); const colors = require("colors"); jokes.getRandomDadJoke(function (joke) { console.log(joke.rainbow); });

The NPM(Node Package Manager) Universe

  • Adding Global Packages

npm i -g cowsay在大路径下面引入global package

npm link cowsay在单个小路径下link引入的package名称,然后在js文件里面require

  • npm init,生成package.json文件:

The NPM(Node Package Manager) Universe

  • 引入包

The NPM(Node Package Manager) Universe

  • 使用别人的开源代码,包含package.json文件,但是不包含node_modules文件,在package.json文件路径下“npm install”,就会自动生成相关依赖文件node_modules。
  •      npm install: 在package.json同一路径下
    • go ahead and install dependencies basaed upon package JSON files, then we can get a file called node_modules

 

 

上一篇:Flutter TextField边框颜色


下一篇:flutter设置沉浸式状态栏