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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jl15988/node-action

v0.0.1-alpha.17

Published

A Nodejs server helper.

Downloads

138

Readme

node-action

介绍

利用 node 快速构建高可用、高效率、高健全的 server

安装

npm install @jl15988/node-action

简单使用

index.js

const {nodeAction, Action, actionInterceptor} = require("@jl15988/node-action");

const userInfo = {
    "id": 1,
    "username": "admin",
    "nickname": "管理员",
    "email": "[email protected]",
    "mobile": "15612345678",
    "sex": 1,
    "avatar": null,
    "loginIp": "192.168.0.8",
    "loginDate": 1731468594935,
    "createTime": 1609837427000,
    "roles": [
        {
            "id": 1,
            "name": "超级管理员"
        },
        {
            "id": 2,
            "name": "普通角色"
        }
    ],
    "dept": null,
    "posts": [
        {
            "id": 1,
            "name": "董事长"
        }
    ],
    "socialUsers": []
}

// 创建用户控制器
const UserAction = new Action('UserAction', (action) => {

    // 设置 user action 的路由前缀
    action.mapping('/user')

    // 获取用户信息接口
    action.get('/get', (requestInfo) => {
        // 请求参数
        console.log(requestInfo.params)
        // 返回用户信息
        return userInfo
    })

    // 修改用户信息接口
    action.post('/update', (requestInfo) => {
        // 请求体
        console.log(requestInfo.body)
        // 返回修改结果
        return {
            code: 200,
            message: '修改成功'
        }
    })
})

const interceptors = [{
    // 拦截器名
    name: 'onLoad',
    // 执行排序,如果重复则按添加的顺序,没有顺序的优先级最低
    sort: 0,
    // 解析路由之前的拦截器
    load: (requestInfo, response) => {
        return true
    },
    // 执行路由处理方法之前的拦截器
    before: (requestInfo, response, routeInfo) => {
        return true
    },
    // 执行路由处理方法之后的拦截器
    after: (requestInfo, response, routeInfo, handleResult) => {
        return true
    }
}]

// 统一异常处理器
nodeAction.actionErrorHandler = (request, response, error) => {
    console.error(error)
}

// 统一返回数据处理器
nodeAction.actionResultHandler = (request, response, res) => {
    console.log(res)
    return res
}

nodeAction
    // 控制器
    .actions([UserAction])
    // 拦截器
    .interceptors(interceptors)
    // 端口号
    .port(3000)
    // 启动
    .start()

执行 node src/index.js 启动

浏览器访问:http://{本地地址}:3000/user/get