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

froyo

v0.9.7

Published

A simple, micro-framework for Node.js.

Downloads

37

Readme

#Froyo ##Node.js Micro Awesomeness froyo is a simple, expressive node.js micro-framework.

##Changelog v0.9.7

  1. Exposed app.router (can be used in the middleware stack now)
  2. Abstracted the response utilities into a seperate module
  3. app.set("template") is now app.set("view engine")
  4. res.render is better now
    app.set("views", "viewDirectory"); // default is ./views
    app.set("view ext", ".mustache") // default extension .html
    // in callbacks
    res.render("test") // renders viewDirectory/test.mustache, default is ./views/test.html
  5. String routes (EXPLAIN!)

##Install

###With npm:

npm install froyo

###Install from source:

git clone git://github.com/PyScripter255/frozen-yogurt.git

cd frozen-yogurt

npm install

##Example

var froyo = require("froyo")
var app = froyo.app();

var thePosts = {
    "bob": ["Froyo is cool", "Have you tried it?"],
    "joe": ["Really?", "Nope"]
}

function givePosts(req, res){
    res.writeHead(200, {"Content-Type": "text/json"})
    res.end(JSON.stringify(thePosts))
}

function index(req, res){
    res.render("./index.html", {lasestPost: "foobar"}) // using the default mustache templates
}

var postComment = {
    post: function(req, res){
        res.writeHead(200, {"Content-Type": "text/json"})
        var comment = "";
        req.on("data", function(data){
            var comment += data;
        })
        req.on("end", function(){
            posts[req.params.post].addComment(JSON.parse(comment))
        })
        }
}

app.scoop({
    "/": index,
    "/posts": givePosts,
    "/comment/:post": postComment
})

app.start(8080);

##License The MIT License

Copyright (c) 2012 James A. Eschrich

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

##API Docs:

###Froyo

Main namespace. Contains all of connect.middleware

###Froyo.app [Function]

returns a new app

###App [Object]

It's an extended version of the connect server. It has the following extra methods:

####App.scoop

Adds request handlers to your app. It can be called at anytime, and the routes are based on routes.

Takes an Object mapping paramter

#####Example

app.scoop({
    '/': index,
    '/posts/:post': getPost
})

####App.set Sets a key to a value.

app.set("mode", "production")

There are only two important key/value pairs. One is the template key, which is set to the template function (see extend on the wiki).

app.set("template", templateFunction)

By default, this is set to froyo's built in mustache template renderer.

The other is the mode:

app.set("mode", mode);

Setting the mode to anything other than development (the default) stops full error logging. Other than that, you can set key to any value.

####App.get Returns a value by getting a key:

app.get("mode") // development

####App.start

Takes a port argument. Starts the app at the port specified.

#####Example

app.start(8080)

Exactly like doing this:

http.createServer(app).listen(8080)

###Froyo request handlers

Just like node.js request handlers:

function(req, res){

}

However there are some differences.

  • req.params.* is populated with the field you specified in the url routes.
app.scoop({
    '/posts/:post': posts // req.params.post is populated
})
  • You can also pass objects
var index = {
    get: function(req, res){
    ...
    },
    post: function(req, res){
    ...
    }
}
app.scoop({
    '/': index
})

If you pass a function, that function is served for GET requests.

function index(req, res){
...
}

//and

var index = {
    get: function(req, res){
    ...
    }
}

//are the same thing

//but!
function index(req, res){
...
}

//and

var index = {
    get: function(req, res){
    ...
    },
    post: function(req, res){
    //exact same function
    }
}
//are not the same!
  • You have the res.render function
function index(req, res){
    res.render(file, optionsOrConfig) 
    // use app.set("template", yourTemplateName) to change from default template (mustache)
}

Froyo ships with mustache templates, enabled by default.

function index(req, res){
    res.render("./index.html", {name: "Example"})
}
  • You have the res.sendFile function, which streams a file to the client
function index(req, res){
    res.sendFile(path);
}
  • and the res.redirect function
function index(req, res){
	res.redirect(path)
}

##Developer Guide

###Code Guide

  1. Use streams if possible.
  2. The API should be simple, expressive and unopinionated

###Work with the code

  1. Install the dev dependencies npm install -d
  2. Install with npm install
  3. Test with npm test