A simple, micro-framework for Node.js.
froyo is a simple, expressive node.js micro-framework.
res.renderis better now
appset"views" "viewDirectory"; // default is ./viewsappset"view ext" ".mustache" // default extension .html// in callbacksresrender"test" // renders viewDirectory/test.mustache, default is ./views/test.html
npm install froyo
git clone git://github.com/PyScripter255/frozen-yogurt.gitcd frozen-yogurtnpm install
var froyo = require"froyo"var app = froyoapp;var thePosts ="bob": "Froyo is cool" "Have you tried it?""joe": "Really?" "Nope"reswriteHead200 "Content-Type": "text/json"resendJSONstringifythePostsresrender"./index.html" lasestPost: "foobar" // using the default mustache templatesvar postComment =reswriteHead200 "Content-Type": "text/json"var comment = "";reqon"data"var comment += data;reqon"end"postsreqparamspostaddCommentJSONparsecommentappscoop"/": index"/posts": givePosts"/comment/:post": postCommentappstart8080;
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.
Main namespace. Contains all of connect.middleware
returns a new app
It's an extended version of the connect server. It has the following extra methods:
Adds request handlers to your app. It can be called at anytime, and the routes are based on routes.
Takes an Object mapping paramter
appscoop'/': index'/posts/:post': getPost
Sets a key to a value.
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).
By default, this is set to froyo's built in mustache template renderer.
The other is the 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.
Returns a value by getting a key:
appget"mode" // development
Takes a port argument. Starts the app at the port specified.
Exactly like doing this:
Just like node.js request handlers:
However there are some differences.
req.params.*is populated with the field you specified in the url routes.
appscoop'/posts/:post': posts // req.params.post is populated
var index =appscoop'/': index
If you pass a function, that function is served for GET requests.
//andvar index =//are the same thing//but!//andvar index =//exact same function//are not the same!
resrenderfile optionsOrConfig// use app.set("template", yourTemplateName) to change from default template (mustache)
Froyo ships with mustache templates, enabled by default.
resrender"./index.html" name: "Example"
npm install -d