Giter VIP home page Giter VIP logo

fire's Introduction

Node on Fire: an isomorphic JavaScript framework ๐Ÿ”ฅ

Build Status License Badge

Node on Fire Logo

An isomorphic JavaScript framework built on top of Node.js, AngularJS, PostgreSQL, Express, Knex.js and more.

With Node on Fire you write apps faster than ever, completely in JavaScript, backed by solid technologies such as PostgreSQL and AngularJS.

Node on Fire includes a list of modules and features to help you write apps faster:

Dependency injection

Angular's dependency injection is great. That's why, in Node on Fire, that dependency injection is also available in the back-end.

You can even use the simpler implicit annotation because Node on Fire seamlessly replaces implicit annotations with inline array notations in the build phase.

app.post('/api/users', function(UserModel, request) {
    return UserModel.create(request.body)
        .then(function(user) {
            return user;
        });
});

Isomorphic services

When you create a service, it's available on both the front- and the back-end. This makes it easy to re-use code in your UI but also in your back-end logic.

// This creates a GET route and returns 123 from MyService (in the back-end).
app.get('/api/value', function(MyService) {
    return MyService.getValue();
});

// This creates a controller and sets the scope's value to 123 from MyService (in the front-end).
app.controller('/', function MyController(MyService, $scope) {
    $scope.value = MyService.getValue();
});

// This is an isomorphic service, available in both the front- and the back-end.
app.service(function MyService() {
    this.getValue = function() {
        return 123;
    };
});

Data model (ORM)

It's easy to declare your data model and all associations (one-to-one, one-to-many and many-to-many).

app.model(function TodoItem(TodoListModel) {
	this.list = [this.BelongsTo(TodoListModel), this.Required];
	this.name = [this.String, this.Required];
	this.completed = [this.Boolean, this.Required, this.Default(false)];
	this.createdAt = [this.DateTime, this.Default('CURRENT_TIMESTAMP')];
});

app.model(function TodoList(TodoItemModel) {
	this.items = [this.HasMany(TodoItemModel), this.AutoFetch];
	this.createdAt = [this.DateTime, this.Default('CURRENT_TIMESTAMP')];
});

Migrations

All changes to your data model are applied through migrations. This makes it super easy to share your data model. You do not need to write migrations yourself, instead, migrations are generated automatically based on the changes of your models.

Migration.prototype.up = function() {
	this.models.createModel('TodoItem', {
		id: [this.UUID, this.CanUpdate(false)],
		list: [this.BelongsTo(this.models.TodoList), this.Required],
		name: [this.String, this.Required],
		createdAt: [this.DateTime, this.Default('CURRENT_TIMESTAMP')]
	});

	this.models.createModel('TodoList', {
		id: [this.UUID, this.CanUpdate(false)],
		items: [this.HasMany(this.models.TodoItem)],
		createdAt: [this.DateTime, this.Default('CURRENT_TIMESTAMP')]
	});
};

Migration.prototype.down = function() {
	this.models.destroyModel('TodoItem');
	this.models.destroyModel('TodoList');
};

Integrated A/B testing

It's trivial to create A/B tests. Tests work with your existing analytics service e.g. Mixpanel.

function StartController(textOfButtonTest, $scope) {
    if(textOfButtonTest == 'A') {
        $scope.buttonText = 'Register for FREE';
    }
    else {
        $scope.buttonText = 'Register now';
    };
}
app.controller('/', StartController);

StartController.prototype.resolve = function() {
    return {
        textOfButtonTest: function() {
            return TextOfButtonTest.participate();
        }
    };
};

Workers and queues

Workers execute background tasks to off-load intensive tasks from the web process. It is super easy to create workers.

app.worker(function MailWorker() {
    this.sendResetPasswordMail = function(user, resetPassword) {
    	var defer = Q.defer();

    	mandrill('/messages/send', {
    		message: {
    			to: [{
    				email: user.email,
    				name: user.name
    			}],
    			...
    		}
    	}, defer.makeNodeResolver());

    	return defer.promise;
    };
});

It's easy to queue a background task from a web process which the worker executes in a worker process.

app.post('/api/forgot-password', function(request, MailWorker, UserModel) {
    return UserModel
        .getMe(request)
        .then(function(user) {
            return MailWorker.sendResetPassword(user, user.resetPassword);
        });
});

Smart caching

To make your app feel even more snappy, Node on Fire utilizes smart caching. Node on Fire instantly shows a result if a cache is available, and quickly replaces it with a fresh version from your back-end.

Node on Fire automatically purges any cache when a related model gets created or updated.

// retrieve a recipe
RecipeModel.findOne({id: $route.params.id}, {autoReload: true, cache: 1000 * 60 * 5})
    .then(function(recipes) {
        // recipes
    });

Config management

All your config is stored in the .env file (this file shouldn't be tracked in version control), but you can use the fire command line interface to manage the config. You can e.g. set NODE_ENV to production by invoking fire config:set NODE_ENV=production or view your config by invoking fire config.

$ fire config
DEBUG:
NODE_ENV:     development
SESSION_KEYS: XI4frrvs+z1JU9auFEmOIAtM...FL3di8Eysw==
DATABASE_URL: postgres://[email protected]/todomvc

Next steps

Getting started

Install Node on Fire globally:

$ npm install -g fire

Create your first app:

$ fire apps:create helloworld

Run your app:

$ cd helloworld/
$ fire run

Examples

We've created several example project which illustrate the different features of Node on Fire. It's also a good reference to use when starting your first Node on Fire app.

http://nodeonfire.org/examples

Contribute

Do you want to contribute? Great! We can always use some help. Reach out to us or go ahead and work on a rate limiting module, a fire watch feature or something else.

Beta releases

From version 0.41.0 and later, every odd numbered minor release is a beta release. Every even numbered minor release is considered a stable release.

Stay up-to-date

Sign up for our newsletter at nodeonfire.org and we'll occasionally send you updates, tips and other news. No spam.

Questions

Open an issue over at GitHub or send a tweet to @nodeonfire.

fire's People

Contributors

martijndeh avatar multimaniac avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.