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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rpc-lite-web

v0.1.10

Published

A simple and easy to use PRC Library

Downloads

15

Readme

快速开始

服务器

由于还在开发中,所以暂时只有Express的版本,更多的Trigger,正在开发

安装命令

npm i rpc-lite --save

express 的加载方法

var express = require(express.js);
var app = express();
var Mrpc = require("./index");
var mrpc = new Mrpc();

//使其不支持跨域
//mrpc.CROS = false;

//获取express的Trigger, 使用express的路由
app.use("/api",mrpc.getTrigger("express"));

app.listen(80);

绑定函数方法

mrpc.add("test",(p1,p2)=>{
    //可以直接返回 或者选择 返回Promise对象
    return Promise.resolve("test success");
});

获取附件

mrpc.add("test",(p1,p2)=>{
    //通过 this.file 来获取附件
    //this.file 是一个对象,里面包含着你上传的附件,通过上传时参数的名字获取
    //this.file["f1"] 这样获取到的是一个f1附件数组(因为一个参数,可能附带多个附件)
    
    //获取附件的名字
    console.log(this.file["f1"][0].filename);

    return "上传文件成功";
});

浏览器

由于这个库直接基于Promise下开发的,所以浏览器需要加入polyfill

在使用前,请插入库

<!-- Promise的polyfil ,如果需要支持IE,则需要加入 -->
<script src="//cdn.bootcss.com/es6-promise/4.0.5/es6-promise.auto.min.js"></script>


<!-- sql-lite的web版,加载方式还支持 CommonJS,AMD,CMD -->
<script src="//meislzhua.github.io/rpc-lite/dist/mrpc.compile.min.js"></script>

初始化对象


//直接根据路由初始化
var mrpc = new Mprc("/api");

//使用完整路径初始化(记得带上协议),可以跨域
var mrpc = new Mprc("http://local/api");

执行远程函数

//调用方式
//mrpc.run(funcName[,arg1,arg2...])

mrpc.run("test","参数1","参数2").then(function(result){
    //这里打印出远程函数的返回值
    console.log(result);
}).catch(function(err){
    //发生错误的时候,则会触发catch,包括 函数运行发生错误(包括手动抛出),找不到函数等
    //err.code 错误码
    //err.message 错误信息
    //err.data 错误数据(手动throw非Error类型数据,云函数返回Promise.reject 的时候,才有数据)
})

使用扩展

//扩展函数
mrpc.extend({
    //给函数设置附件
    file: {
        //input[type=file] 的id
        el: ["f1","f2"],
        progress:function(p){
            console.log("已发送:",p.loaded,"总大小:",p.total)
        }
    }
}).run("test","参数1","参数2").then(function(result){
    //这里打印出远程函数的返回值
    console.log(result);
})

前端测试方法

后台还没编写好相应的API的时候,可以先用本方法用作开发时的测试

mrpc.isDebug = true;

//添加测试函数
mrpc.debugAdd("localTest",function(){
    var whatYouWant = {want:true};
    return whatYouWant;
})