Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

faraday

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faraday

A lightweight MVC framework

  • 1.10.2
  • npm
  • Socket score

Version published
Weekly downloads
27
increased by80%
Maintainers
1
Weekly downloads
 
Created
Source

Faraday

A lightweight MVC framework.

To begin, run the following the in the root of your app:

coffee node_modules/faraday/new.coffee

Now you can access faraday throught the folders models, views, and controllers.

The Server

To run the server, run

./develop

If you get this:

-bash: ./develop: Permission denied

Run this:

chmod +x develop

This gives develop executable permission. To get develop to work, you may need to install the ruby gem called sass.

Models and Modooses

I have abandoned the old models folder in favor of the modooses model. You can still use models, but they are deprecated and will be removed in subsequent versions.

A modoose is a humorous malamoneau of "model" and "mongoose". (I can hear you laughing). Each modoose corresponds to a mongoose model in a coffee file in the modooses folder. To create a modoose called Foo, save the file ./modooses/Foo.cofffee:

fooSchema = # a mongoose schema for Foo...

module.exports = require('mongoose').model('Foo', fooSchema)

Faraday will create this model in the database and you can access it asynchronously as:

require('faraday').modoose(({Foo}) -> 
    foo = Foo.find({bar: 'baz'})
    # Do things with the Foo modoose.
)

Views

In your views folder, put files the form filename.html.underscorecoffee. These will be compiled as underscore.js (HTML) templates. You can invoke them as require('faraday').views.filename(scope). The scope object will become the scope in the underscore.js template. That way you can pass variables and data for the template to render.

Controllers

In your controller folder, put coffeescript files. If you create a file ./controllers/foo.coffee with the following:

myRequestHandler = (req, res) -> 
    #handle the request
    
module.exports = myRequestHandler

Then navigate to localhost:3000/foo, myRequestHandler will be invoked with two arguments: the node.js request object and response object. I commonly require views in a controller and invoke some corresponding view.

Faraday will map directories in the controllers folder to path components in the url. For example, if you save the aforementioned coffescript as ./controllers/several/nested/directories/foo.coffee myRequestHandler will be invoked when you navigate to localhost:3000/several/nested/directories/foo. You can also create path components by nesting the routing object:

myRequestHandler = (req, res) -> 
    #handle the request
    
module.exports = 
    several:
        nested:
            directories:
                foo: myRequestHandler

You can inspect how this works by reading node_modules/faraday/route.coffee.

FAQs

Package last updated on 18 Jan 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc