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

powerjs

v0.2.5

Published

基于Express的Web开发架构

Downloads

75

Readme

PowerJS -- 基于Express的Web开发架构

使用方法

$ npm install powerjs-cli -g
$ powerjs create    

框架目标

快速构建nodejs开发架构,提升开发速度,提升代码可读性

全局变量

C变量 全局配置信息集合 U变量 通用辅助函数集合 D变量 数据库对象集合 L变量 日志对象,用户调试

配置信息

网站根目录

root: __dirname

网站端口

port: 3000

运行模式

env: 'develop' || 'production'

网站图标

favicon: './favicon.ico'

网站主题,对应各app下视图文件夹中的主题文件夹

theme: 'default'

数据库配置信息,可在该属性下定义多个数据库链接,通过type属性指明数据库类型,目前仅支持mongodb和mysql数据库

db: {
    video_db: {
        type: 'mongodb',
        host: '127.0.0.1',
        port: 27017,
        database: 'test',
        username: null,
        password: null
    },
    mysql: {
        type: 'mysql',
        host: '127.0.0.1',
        port: 3306,
        database: 'test',
        username: 'root',
        password: ''
    }
}

路由,定义网站的访问规则

router: {
    default: {
        package: 'main',
        controller: 'index',
        action: 'index'
    }
}

视图引擎,默认为swig 可通过命令 powerjs set engine 进行修改,目前仅支持swig jade ejs三种

engine: {
    type: 'swig', // swig, jade, ejs
    config: {}
}

控制器

框架定义了常用的控制器方法,使用时通过js继承的方式继承控制器基类进行开发

file: /apps/demo/controller/index.controller.js

var pjs = require('powerjs');
var BaseController = pjs.controller;

var IndexController = function () {
    BaseController.apply(this, arguments);
};
IndexController.prototype.__proto__ = BaseController.prototype;

IndexController.prototype.indexAction = function () {
    this.view.framework = 'PowerJS';
    this.render();
};

IndexController.prototype.jsonService = function () {
    this.send({Hello: 'PowerJS'});
};

module.exports = IndexController;

/demo/index/index 执行indexAction方法

/service/demo/index/json 执行jsonService方法

视图文件

定义页面的渲染主体,视图文件与控制器方法保持一一对应的渲染方式,控制器也可以通过修改render参数渲染其他视图。

file: /apps/demo/view/default/index/index.view.swig

<!doctype html>
<html>
...
<body>Hello {{ framework }}</body>
</html>

模型

框架定义了两个简单的数据库基础模型文件,通过继承基础模型类,可以快速开发数据库相关功能。

Mongodb模型文件: require('powerjs').model.mongo;

Mysql模型文件: require('powerjs').model.mysql;

var BaseModel = require('powerjs').model.mongo; // powerjs提供的基础数据库操作函数,mysql暂未提供

module.exports = U.extend(BaseModel, {
    db: D.mongodb, // 配置文件中定义的数据库链接
    collection: D.mongodb.collection('test'),
    // 自定义的模型层函数
    demo: function (callback, scope) {
        this.fetchRows({}, function (rows) {
            callback && callback.call(scope, rows);
        });
    }
});

静态文件

框架根目录下的static文件夹用于存储系统中各模块通用的静态文件,apps下各应用的static文件夹用于存储app私有的静态文件。

访问公共静态文件的方式

/static/lib/jquery.js

访问私有静态文件的方式

/apps/demo/static/demo.js

日志

框架启动时会在根据录下创建logs文件夹用于存放日志文件

开发程序时,可以通过全局变量L将调试信息写入日志文件

L.debug(new Error('demo'));