强大npm下的实用库(持续更新)

request 简化的HTTP请求的客户端(star:16074)
request被设计成可以进行http调用的最简单的方法。它支持HTTPS,并在默认情况下重定向。

//基本写法,支持promise
request
  .get('http://google.com/img.png')
  .on('response', function(response) {
    console.log(response.statusCode) // 200
    console.log(response.headers['content-type']) // 'image/png'
  })
  .pipe(request.put('http://mysite.com/img.png'))

cheerio 是nodejs的抓取、解析HTML页面模块,为服务器特别定制的,快速、灵活、实施的jQuery核心实现。适合各种Web爬虫程序。(star:12684)

const cheerio = require('cheerio')
const $ = cheerio.load('<h2 class="title">Hello world</h2>')

$('h2.title').text('Hello there!')
$('h2').addClass('welcome')

$.html()
//=> <h2 class="title welcome">Hello there!</h2>

axios基于Promise 的 HTTP 请求客户端,可同时在浏览器和 node.js 中使用。(star:22700)

// Make a request for a user with a given ID
axios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (response) {
    console.log(response);
  });


fetch一个兼容window.fetch特性的polyfill

fetch函数是一个基于promise的用于替代传统浏览器XMLHttpRequest的替代方案(star:14917)

//Usage
fetch('/users.json')
  .then(function(response) {
    return response.json()
  }).then(function(json) {
    console.log('parsed json', json)
  }).catch(function(ex) {
    console.log('parsing failed', ex)
  })

jsdom Nodejs抓取、解析HTML网页模块 jsdom(star:7904)

const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
console.log(dom.window.document.querySelector("p").textContent); // "Hello world"

nodemeiler是一个用于Node.js应用邮件发送模块。(star:7966)

'use strict';
const nodemailer = require('nodemailer');

// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
    host: 'smtp.example.com',
    port: 465,
    secure: true, // secure:true for port 465, secure:false for port 587
    auth: {
        user: 'username@example.com',
        pass: 'userpass'
    }
});

// setup email data with unicode symbols
let mailOptions = {
    from: '"Fred Foo " <foo@blurdybloop.com>', // sender address
    to: 'bar@blurdybloop.com, baz@blurdybloop.com', // list of receivers
    subject: 'Hello ✔', // Subject line
    text: 'Hello world ?', // plain text body
    html: '<b>Hello world ?</b>' // html body
};

// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
        return console.log(error);
    }
    console.log('Message %s sent: %s', info.messageId, info.response);
});

node-schedule是一个基于时间的任务调度器,而不是基于交互,可用来定时执行一个爬虫(star:3672)


node-cron一个基于node的简单定时作业调度器(star:381)

Paste_Image.png

http-server一个简单零配置命令行搭建http服务器的工具(star:5226)

 npm install http-server -g
 http-server [path] [options]

electron使用javascript、css、html搭建跨平台桌面应用的开源框架,强悍至极!(star:47729)

# Install as a development dependency
npm install electron --save-dev

# Install the `electron` command globally in your $PATH
npm install electron -g


# Clone this repository
git clone https://github.com/electron/electron-quick-start
# Go into the repository
cd electron-quick-start
# Install dependencies
npm install
# Run the app
npm start

node-lru-cache基于node的使用最近最少使用算法的策略进行数据缓存库(star:1416)

npm install lru-cache --save

var LRU = require("lru-cache")
  , options = { max: 500
              , length: function (n, key) { return n * 2 + key.length }
              , dispose: function (key, n) { n.close() }
              , maxAge: 1000 * 60 * 60 }
  , cache = LRU(options)
  , otherCache = LRU(50) // sets just the max size

cache.set("key", "value")
cache.get("key") // "value"

// non-string keys ARE fully supported
var someObject = {}
cache.set(someObject, 'a value')
cache.set('[object Object]', 'a different value')
assert.equal(cache.get(someObject), 'a value')

cache.reset()    // empty the cache

es6-promise让es6 promise能兼容更多浏览器,一个polyfill库(star:4677)

npm install es6-promise

var Promise = require('es6-promise').Promise;

Numeral-js用于格式化和操作数字的JavaScript库(star:5214)


nprogress非常漂亮、轻量的页面加载进度条效果


node_redis基于node的redis内存数据库,其中一个策略可用于替代上面的lru cache库(star:8000)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Swift版本点击这里欢迎加入QQ群交流: 594119878最新更新日期:18-09-17 About A cu...
    ylgwhyh阅读 25,565评论 7 249
  • 有亲密的朋友告诉我,你的蒙娜丽莎笑让人瘆得慌。 我的笑,给我精心准备的演出拉出一根臭烘烘的粑粑。 我是一个壳子,从...
    兰岚Lillian阅读 270评论 0 0
  • 残酷的现实总会打击个人的理想,现在的中国处于经济变革的大时代,如今社会即将阶级固化;个人不过是时代长河中的一个水分...
    希夷子阅读 252评论 0 1
  • 文/小残夜半凉 你是我心底蓝色的沙漠 我却是你眼里荒芜的灰海。 你总幻想着成为我的贝壳 我却不是那颗沙砾。 于是我...
    骑马上岸的人阅读 218评论 5 11
  • 20170709 阵雨 今天听了老师的课真正体会到了营销的魅力,原来每个步奏都是有方法的,回想之前跟客户沟通的过程...
    璞玉_e048阅读 206评论 0 0