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

simple-res

v0.0.2

Published

simple res

Readme

simple-res


简化同时需要应付 ajax和http的请求, 例如删除一个记录,如果是http请求,返回用户删除成功信息,并跳转到一个页面,或者ajax请求,直接返回删除成功
依赖模块

1. simple-res依赖express和session
安装

npm install simple-res
使用

    var app = require('express')();
    app.use(require('simple-res'));

    app.get('/delte/:id', function(req, res, next) {
       var ret = 0;
       var msg = '';
       //如果successDone是字符串,当ret =0,是将执行 res.redirect(successDone),并将msg放入到 req.session.crossPageSuccess,res.locals.success 中
       var successDone = function() {
        console.info("成功时执行");
       }
       //如果failDone是字符串,当ret !=0,是将执行 res.redirect(failDone),并将msg放入到 req.session.crossPageError,res.locals.error 中
       var failDone = function() {
        console.info("失败时执行");
       }
       var otherMsg = 'wangdana';
        if (id === 1) {
            //删除成功
            res.simpleResponse(ret, successDone, failDone, {errMsg: msg, otherMsg: otherMsg), req);
        } else {
            ret = -1;
            msg = '删除失败';
            res.simpleResponse(ret, successDone, failDone, {errMsg: msg, otherMsg: otherMsg), req);
        }
    });
ajax 请求返回格式 {"ret":0,"code":0,"errMsg":"操作成功","redirectUrl":"http://localhost:3000/line/self","otherMsg":1}
http 请求将直接执行 successDone,或者failDone