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

purenode

v1.0.3

Published

nodejs web framework

Downloads

3

Readme

purenode

nodejs 学习型的web框架,很小的一个框架,初步实现了服务器,路由请求转发,控制器,模板引擎等基本框架功能,共初学者学习使用。purenode的设计思想是让开发者像开发php web一样的开发nodejs web应用。如果是熟悉Herosphp或者ThinkPHP的话,那么这个框架你使用起来应该是得心应手的。

安装

1.作为模块安装

npm install purenode

2. 作为项目安装(推荐)

git clone [email protected]:blackfox/purenode.git

#然后直接在项目根目录下做开发就好了。

框架目录结构

app.js app入口文件
config.js app配置文件 
www  应用程序文件目录
    |-- demo //模块目录
		|-- action 控制器目录
		|-- views 模板目录
public 静态资源目录(可更改) 
framework 框架根目录 
	|-- purenode.js 框架的入口文件 
	|-- request.js http请求处理
	|-- response.js 响应处理
	|-- router.js 路由处理
	|-- server.js 服务器
	|-- model.js 数据模型
function.js 全局函数
template-helper.js art-templte模板引擎的扩展解析

创建应用服务

vim app.js (创建app文件)


var purenode = require("./purenode.js");

var app = purenode();
app.static("/public/");
app.listen(8888);

创建控制器

vim www/demo/action/UserAction.js (创建控制器,编写控制器逻辑代码)

"use strict"

module.exports = {


	// index page
	index : function(req, res) {

		var params = req.getParameters();
		var data = {
			title : "欢迎使用purenode框架",
			hello : "Welcome, this is the index page",
			params : params
		};
		
		var app = req.getApp();
		var db = app.getDB();
		var model = F_require("model");
		var userModel = model.getInstance(app, "user");
		var date = new Date().format("yyyy-MM-dd hh:mm:ss");
		var user = {username:"xiaoming", name:"小梦", password:"123456", addtime:date};

		//添加数据
		//userModel.add(user, function(e, r) {
		//	console.log(e,r);
		//});

		//删除数据
		//userModel.delete(5, function(e,r) {
		//	console.log(e,r);
		//});

		//批量删除
		//userModel.deletes("id > 8", function(e, r) {
		//	console.log(e, r);
		//});

		//修改数据
		//user.id = 6;
		//user.name = "xiaoyang333";
		//userModel.update(user, function(e, r) {
		//	console.log(e,r);
		//});
		
		//批量更新
		//user.addtime = new Date().format("yyyy-MM-dd hh:mm:ss");
		//userModel.updates(user, "id > 6",  function(e, r) {
		//	console.log(e, r);	
		//});
		
		userModel.count(function(e, r) {
			console.log(e,r);
		});

		//查询数据
		db.query("select * from user", function(err, rows) {
		
			if ( err ) {
				console.log(err);
			} else {
				data.users = rows;
			}

			res.display("index", data);
		});

	}
}

创建模板

vim www/demo/views/index.html

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>{{title}}</title>
	<link rel="stylesheet" media="all" href="/public/css/style.css">
</head>
<body>
<h1>{{hello}}</h1>
	<h2>接收到的参数列表</h2>
	{{each params}}
	<h3>{{$index}} : {{$value}}</h3>
	{{/each}}

	<h1>{{F.getUrl("login/index")}}</h1>
	<h1>{{hello | cut:8}}</h1>

	<h2>用户列表</h2>
	<table class="data-table">
		<tr>
			<th>id</th>
			<th>name</th>
			<th>mobile</th>
			<th>email</th>
			<th>create_time</th>
		</tr>

		{{each users as user}}
		<tr>
			<th>{{user.id}}</th>
			<th>{{user.name}}</th>
			<th>{{user.username}}</th>
			<th>{{user.email}}</th>
			<th>{{user.addtime | date:"yyyy-MM-dd hh:mm:ss"}}</th>
		</tr>
		{{/each}}
	</table>

	<img src="/public/images/kazigu.jpg" width="400"/>
</body>
</html>

运行

node app.js

访问

在浏览器输入 http://localhost:8888

热部署

如果你习惯了php的开发环境,你肯定对nodejs这种开发有点不适应,因为每次修改源代码都要重启服务器,跟java一样(当然,nodejs启动肯定比java快些)。你可以通过安装pm2工具来实现热部署。不过有点坑的就是,pm2只能实现模板的热部署,如果你更改了控制器文件还是需要重启服务器的。

npm install -g pm2

pm2 start app.js //启动app
pm2 stop app.js //停止app
pm2 reload app.js //重启app

启动后如图所示: