npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

jwfetch-node

v2.0.2

Published

## 包含功能点

Readme

封装的fetch,nodejs使用

包含功能点

  • 同一时间段重复请求会被缓存过滤掉
  • timeout

使用

封装ajax

import Ajax from "jwfetch-node";

Ajax.defaults.baseURL = "/api";

export const ajax = new Ajax();

拦截

// 请求拦截
ajax.interceptors.request.use(function (mergedConfig) {
  mergedConfig.headers = mergedConfig.headers || {};
  mergedConfig.headers.token = "abcd";
  return mergedConfig;
}, function (err) {
  return Promise.reject(err);
});

// 响应拦截
ajax.interceptors.response.use(function (data) {
  return data.slice(0, 10);
}, function (err) {
  return Promise.reject(err);
});

ajax配置项

url

Type: string

method

Type: string

一般是get、post

baseURL

Type: string

请求url的前缀

headers

Type: object

添加的请求头

data

Type: object

请求数据,一般是个对象{}。

timeout

Type: number

Default: 2 * 60 * 1000,2分钟

过期时间,单位ms。从请求开始,到这个时间如果接口没有响应,则会返回一个失败的promise。

timeoutErrorMessage

Type: string

Default: timeout

过期时间错误提示

timeoutErrorStatus

Type: number

Default: 504

过期时间状态码

credentials

Type: string

Default: include

  • omit:忽略cookie的发送
  • same-origin: 表示cookie只能同域发送,不能跨域发送
  • include: cookie既可以同域发送,也可以跨域发送

mode

Type: string

Default: cors

  • same-origin:该模式是不允许跨域的,它需要遵守同源策略,否则浏览器会返回一个error告知不能跨域;其对应的response type为basic。
  • cors: 该模式支持跨域请求,顾名思义它是以CORS的形式跨域;当然该模式也可以同域请求不需要后端额外的CORS支持;其对应的response type为cors。
  • no-cors: 该模式用于跨域请求但是服务器不带CORS响应头,也就是服务端不支持CORS;这也是fetch的特殊跨域请求方式;其对应的response type为opaque。

isFile

Type: boolean

是否属于文件上传,如果是这样,会根据传递的data,创建一个FormData

isUseOrigin

Type: boolean

为true时,直接返回response,不再处理结果。 一般返回结果不是json对象,比如是流时需要设置此项。

isEncodeUrl

Type: boolean

get请求时是否要进行浏览器编码

cacheTimeout

Type: number

缓存时间

  • 如果是-1,代表不清除缓存。
  • 如果是0,代表不使用缓存。
  • 如果大于0,代表要缓存多长时间,单位是ms。

originHeaders

Type: Headers

如果本身是在接口里进行的二次请求,传递原始的headers

defaultInjectHeaderKeys

Type: string[]

Default: ["x-request-id", "x-b3-traceid", "x-b3-spanid", "x-b3-parentspanid", "x-b3-sampled"]

配合originHeaders使用,如果有这几个字段,将会默认注入