request 簡化的HTTP請(qǐng)求的客戶端(star:16074)
request被設(shè)計(jì)成可以進(jìn)行http調(diào)用的最簡單的方法县好。它支持HTTPS差凹,并在默認(rèn)情況下重定向境氢。
//基本寫法枉氮,支持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頁面模塊抬旺,為服務(wù)器特別定制的弊予,快速、靈活开财、實(shí)施的jQuery核心實(shí)現(xiàn)汉柒。適合各種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 請(qǐng)求客戶端,可同時(shí)在瀏覽器和 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一個(gè)兼容window.fetch特性的polyfill
fetch函數(shù)是一個(gè)基于promise的用于替代傳統(tǒng)瀏覽器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網(wǎng)頁模塊 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是一個(gè)用于Node.js應(yīng)用郵件發(fā)送模塊兽间。(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是一個(gè)基于時(shí)間的任務(wù)調(diào)度器,而不是基于交互正塌,可用來定時(shí)執(zhí)行一個(gè)爬蟲(star:3672)
node-cron一個(gè)基于node的簡單定時(shí)作業(yè)調(diào)度器(star:381)
http-server一個(gè)簡單零配置命令行搭建http服務(wù)器的工具(star:5226)
npm install http-server -g
http-server [path] [options]
electron使用javascript嘀略、css、html搭建跨平臺(tái)桌面應(yīng)用的開源框架乓诽,強(qiáng)悍至極V难颉(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的使用最近最少使用算法的策略進(jìn)行數(shù)據(jù)緩存庫(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能兼容更多瀏覽器,一個(gè)polyfill庫(star:4677)
npm install es6-promise
var Promise = require('es6-promise').Promise;
Numeral-js用于格式化和操作數(shù)字的JavaScript庫(star:5214)
nprogress非常漂亮鸠天、輕量的頁面加載進(jìn)度條效果
node_redis基于node的redis內(nèi)存數(shù)據(jù)庫讼育,其中一個(gè)策略可用于替代上面的lru cache庫(star:8000)