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

lightmvc

v1.0.2

Published

a node mvc framework,like asp.net mvc

Downloads

4

Readme

lightMvc

一个简单轻量的node mvc 框架,类似asp.net mvc.

开始

安装lightMvc

npm install lightmvc --save

使用

添加app.js

var Mvc=require("lightmvc");
var app=Mvc();
//注册路由模板
app.addRouter("/{controller}/{action}/{id}",//路由模板
              {controller:"home",action:"index",id:1},//默认值
			  {id:/\d+/});//用正则表达式匹配来约束参数
			  
app.listen(5566,function(){
	console.log("web server is listening on port 5566");
});

我们要添加控制器和相应视图来处理不同的请求。

在controllers目录下添加一个控制器 home.js

 module.exports = function (req, res) {
     this.index = function (req,res) {
         var model = {
             title: "首页",
             content: "欢迎您使用"
         };
         return res.view(model);
     };
	 
	 this.post_index=function(){
			return "index方法名称添加post_前缀来处理post请求";
	 };
 };

在views目录下添加home/index.htm 视图文件,视图使用razor语法

<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>@model.title</title>
</head>
<body>
@model.content
</body>
</html>

启动web服务

node app.js

现在你就可以访问: http://127.0.0.1:5566/home/index

lightMvc api

app

  1. app.setViews(path) 设置视图文件存放路径, 视图文件后缀为 .html, 使用vash模板引擎( razor语法)

  2. app.setController(path); 设置控制器文件存放路径

  3. app.setStatic(path); 设置静态文件存放路径

  4. app.setCompressFileExtension(extStr); 设置要进行压缩的文件类型,多个文件类型用 逗号隔开 如 css,html,js

  5. app.setExpiresMaxAge(num); 静态文件 最大过期时间 单位秒

req

  1. req.urlData
  2. req.session
  3. req.cookies
  4. req.form
  5. req.routeData
  6. req.files
  7. req.query

res

  1. res.cookie(name,val,opts)
  2. res.view(model,viewName),
  3. res.json(obj),
  4. res.content(contentStr),
  5. res.redirect(url),
  6. res.httpNotFound(),
  7. res.httpForbidden();

具体例子请见demo