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

wee-node

v1.0.12

Published

a middle-node web framework

Downloads

4

Readme

nodeweb

a simple node web library

how to use

first

npm i wee-node --save-dev

second

  server.js
    const wee = require('wee-node') 
    const app = wee()
    app.use('/',function(req,res){
        res.send('hello,world');
    });
    app.listen(8080)

api

app.use(router,callback,callback)

  exzample server.js
    app.use('/',function(res,req){  
        res.write('hello!');  
        res.end();
    })

或者

    app.use('/',function(res,req){    
            res.write('hello!');  
            res.end();
        },  
    function(res,req,next){     
        //进入路由的生命周期,before  
        console.log('hello')   
        next();
    })
    res被添加两个静态方法
    res.send => res.write + res.end
    res.json => 发送json格式的字符串
    req被添加两个静态属性
    req.query=> ?demo=0    ==>  {demo:0}
    req.post=> post的body体。

app.static(realDictory,renamedictory)

app.static('./static');

  localhost:8080/static/index.html  

app.static('./static','img')

  localhost:8080/img/one.png

app.engine(engine)

  exzample server.js
   const laytpl = require('laytpl').__express;
   app.engine(laytpl);
   var options = {name:'hello,wee'}
   app.use('/',function(req,res){
        res.render('./index.html',options,function(err,str){
        res.send(str)     
   })
   })
  index.html
    <html>
    <head>
        <title></title>
    </head>
    <body>
    {{d.name}}
    
    </body>
    </html>     
    
  result
    hello,wee

app.staticnot(callback)

app.listen(port,protocol)

app.listen(8080,'http');

开启端口为8080的服务器,第二个参数默认是 http协议 ,暂时只支持,http,和https

app.chdir(dictory)

app.before(callback)

  exzample server.js
    app.before(function(req,res,next){  
        req.send('hello');
        next();
    })  

在所有请求到来后首先触发这个,需要用next去继续下面的路由行为

tool

wee-file-parse

use

    const app = require('wee-node')();
    const file = require('wee-file-parse');
    const fs = require('fs');
    
    app.use('upload',function(req,res){
        var chunks = [];
        req.on('data',function(chunk){
            chunks.push(chunk);
        });
        req.on('end',function(){
            var data = file(chunks);
            fs.writeFile('/'+data.filename,data,(err)=>{
                if(err){
                    throw err;
                }
                console.log('The file has been saved!');
            })
        })
    })

当将收集到上传的chunks传入到解析tool里面,会返回一个对象,该对象有两个属性,一个是上传的文件的body,一个是上传的文件的name

    data.file
    data.filename