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

easy-route

v0.0.2

Published

a simple router for express.js

Downloads

6

Readme

easy-route

a simple router for express.js. it is based on dir name, filename, method name, just be natural and humanity.

Old days

in some route file such as ./routes/site.js, you may code like this :

exports.github = function(req, res){
    res.render('coming', {title:'coming soon ...', selected:'github'})
}

then you need to exposed the 'github' method manually in app.js or some other file like this :

var site = require('./site')
app.get('/site/github', site.github)

once you add a method in your route file, you have to update app.js to expose it. meanwhile, you have to decide which http method is to be exposed (like GET and POST). once you wanna change it, you have to sync the two files manually. that is really boring,do you think so?

Now

in your app.js file, you could code like this :

require('easy-route').load(app, function(){
    http.createServer(app).listen(app.get('port'), function(){
        console.log("Express server listening on port " + app.get('port'));
    });
})

and it is over! just enjoy yourself, easy-route will help you finish the boring exposed jobs.

Exposed

for the file ./routes/site.js, the exposed url/api is :

/site/github

for the file ./routes/index.js, default settings has removed 'index'.however, you can change it simply.

/method_name

for the file ./routes/site/child/main.js, if the exports has a index method, the exposed api/url will be :

/site/child/main

for some other method as 'test', it will be :

/site/child/main/test

Http Method

generally, we use app.all to expose all the method, but you can simply change it like this :

exports.github = function(req, res){
    'post'
    res.render('coming', {title:'coming soon ...', selected:'github'})
}

now the github method is http post only, you can also set it to get and so on.

Caution

take a look when your script file's name is index.js or your file has a index method. for example, when you organize you routes folder, be careful on this condition :

./routes
    site.js (has a index method) => /site/
    index.js (has a site method) => /site

well, this may be problem and is a little weird. but i will not solve it just because i am strongly against the method named index. it is totally meaningless! do not make a index file or method, take it as the better practice.

Bugs

a know bug to fix. it happens when you use aop or some other utility like underscore's wrap function

exports.github = _.wrap(expoort.github, function(fn, req, res, next){
    //code here
})

now the toString method can not get the original function's directive such as get / post.

i am still trying to find a better way to solve this problem.

if you have any good idea, report it to me.