1.0.5 • Published 9 years ago

firewire v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
9 years ago

firewire is a modular ecosystem to help build firebase apps in express.

Since it's all underpinned by express, you can still use any other middleware you want.

Create your express app

Don't have express generator, get it - $ npm install express-generator -g

Create an express app via express generorater. Note that we use jade templates to pass firewire data to the front end.

$ express myapp

Install dependancies

$ cd myapp
$ npm install

Add a public node_modules in express

This will allow you to install firewire public modules. This is a good thing.

$ cd public
$ npm init

follow the prompts to create a blank app, which will create a node_modules folder when you install something into it

firewire

If you just added your public node_modules, then you'll need to get back to the root of your app!

Once you're back at the root of your app - install firewire

$ npm install firewire --save

Configure firewire

// index.js in express...
    
var express = require('express');
var router = express.Router();
var firewire = require("firewire");

// Use your own firebase url!!!
firewire.load = {
	url : "https://your-firebase-project.firebaseio.com/"
};

Now you can use firewire in place of res.render to dynamically load a template and inject firebase data into it.

Like this...

router.get('/:page/id/:instance', function(req, res, next) {
	firewire.wire(req,res,firewire.load,[
		{"ids/:instance" : "home"},
		{"pages/:page" : "page"}
	]);
});

Using the above example, if you goto localhost:3000/admin/id/123
firewire will use admin.jade from your views folder
firewire will then expose fw.home and fw.page to the jade template.
fw.home will be populated with data from https://your-firebase-project.firebaseio.com/ids/123
fw.page will be populated with data from https://your-firebase-project.firebaseio.com/pages/admin

Use that data in your jade templates #{fw.home} ... #{fw.page}

Template selection

  • Using :page tells firewire to use that jade template
  • If you don't wan't to use :page, you can still tell firewire what template you want to use with req.params.page = "page-name";

Eg. This will route to admin.jade

/*Dynamic Page and Data Loader */
router.get('/admin/:instance', function(req, res, next) {
	req.params.page = "admin";
	firewire.wire(req,res,firewire.load,[
		{"drafts/:instance" : "itemType"}
	]);
});

Static Data

You can also parse through static (non-firebase) data with firewire.load.static

router.get('/admin/:instance', function(req, res, next) {
	req.params.page = "admin";
	firewire.load.static ={'title' : "some static data"};
	firewire.wire(req,res,firewire.load,[
		{"drafts/:instance" : "itemType"}
	]);
});

You can then plug this into a jade template with #{static.title}

Running your app in local

Now if you have the following route set up

router.get('/:page/id/:instance', function(req, res, next) {
	firewire.wire(req,res,firewire.load,[
		{"ids/:instance" : "home"},
		{"pages/:page" : "page"}
	]);
});

And you've added data in firebase at:

ids
    123 : "Some data"
pages
    admin : "some data"

And you have a template called admin.jade in your views folder using #{fw.home} and / or #{fw.page}

And you run your app...

Use something like nodemon so your app automatically restarts on code changes

$ npm install nodemon -g

To run...

$ nodemon

Goto your browser at localhost:3000/admin/id/123 and your app should automatically route to admin.jade and plug in the firebase data.

Public Modules

Providing that you've set up your public node_modules (explained near top of page) then just...

$ cd public

then just $npm install ... whatever public module you want.

Check out...

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago