Build scalable, Node.js-powered REST JSON APIs with almost no code.
JavaScript
Latest commit 083e112 Jan 22, 2017 @zacharygolba zacharygolba committed on GitHub release: v1.1.6 πŸ”§ (#660)
Permalink
Failed to load latest commit information.
bin fix: we should check for lux under the dependency key in package.json… Jan 17, 2017
decl deps: update flow-bin to version 0.37.4 πŸš€ (#587) Dec 26, 2016
examples release: v1.1.6 πŸ”§ (#660) Jan 23, 2017
flow-typed/npm deps: update flow-bin to version 0.38.0 (#647) Jan 19, 2017
guide docs: add preliminary guide files (#554) Dec 6, 2016
lib deps: update babel-preset-lux to version 2.0.1 (#570) Dec 17, 2016
src fix: recursive readdir is broken (#659) Jan 23, 2017
test release: v1.1.5 πŸ”§ (#658) Jan 21, 2017
.babelrc deps: update babel-preset-lux to version 2.0.1 (#570) Dec 17, 2016
.editorconfig chore: .editorconfig file (#119) May 21, 2016
.eslintignore dx: use flow-typed instead of custom type declarations when possible (#… Nov 10, 2016
.eslintrc.json chore: improve ci config and process (#627) Jan 14, 2017
.flowconfig deps: update flow-bin to version 0.38.0 (#647) Jan 19, 2017
.gitignore chore: improve ci config and process (#627) Jan 14, 2017
.npmignore docs: finalize public api docs for 1.0 release (#418) Oct 19, 2016
.remarkrc chore: add markdown linter (#474) Oct 20, 2016
CHANGELOG.md release: v1.1.6 πŸ”§ (#660) Jan 23, 2017
LICENSE Initial Commit Apr 8, 2016
README.md docs: fix broken logo in readme (#555) Dec 6, 2016
ROADMAP.md chore: add markdown linter (#474) Oct 20, 2016
appveyor.yml chore: add gitter integrations (#651) Jan 19, 2017
circle.yml chore: add gitter integrations (#651) Jan 19, 2017
codecov.yml chore: add gitter integrations (#651) Jan 19, 2017
mocha.opts chore: improve ci config and process (#627) Jan 14, 2017
package.json release: v1.1.6 πŸ”§ (#660) Jan 23, 2017
rollup.config.js chore: improve ci config and process (#627) Jan 14, 2017

README.md

Lux

CircleCI branch AppVeyor Codecov branch David npm Gitter

A MVC style framework for building highly performant, large scale JSON APIs that anybody who knows the JavaScript language and its modern features will understand.

* Inspired by Rails, Ember, and React.

Disclaimer:

This isn't another wrapper around Express or a framework for building frameworks. This also isn't a replacement for server-side frameworks that render DHTML.

Check out the Medium Article!

What?

Features

  • Automatic CRUD actions in controllers
  • Automatic pagination, sorting, filtering via query params in controllers
  • CLI for eliminating boiler plate
  • JSON API 1.0 compliant out of the box
  • Optimized database queries based on serialized attributes and associations
  • Highly extensible - just write reusable JavaScript functions
  • Pairs nicely with client-side JavaScript applications 🍷
  • Easy to contribute
  • Routes are stored and accessed via a Map not an Array
  • Embraces ES2015 and beyond
    • Classes
    • Modules
    • Promises & async/await
    • Arrow Functions
    • etc.

Philosophies

Minimal API surface area

Lux uses JavaScript's standard library rather than creating a ton of functions you'll have to learn and remember.

After your learn how to use it, you'll rarely need to look at the docs.

Pure functions are awesome

Or more appropriately somewhat pure functions are awesome.

Serving content is done by returning objects, arrays, or other primitives rather than calling res.end(/* content */); and returning nothing.

Convention over configuration

Rails and Ember are great because they make hard decisions for you and make it possible to submit a PR on your first day at a new company. This is rare with Node server frameworks.

Why?

Frameworks like Rails are pretty great. You can build amazing applications in a reasonable amount of time without a ton of developers working on a project. They have their limitations though. They can be slow and sometimes hard to scale. Not to mention WebSocket support being so-so.

Node to the rescue.

It's fast, it allows the developer to get low level with a relatively simple API, WebSockets are stable and supported out of the box, and last but not least it's just JavaScript.

Not so fast (metaphorically speaking).

The last bit there "It's just JavaScript" has actually been somewhat of a double-edged sword. This has positioned Node as a "great prototyping tool" or "only used for micro services."

I can somewhat see why people would think that when returning a list of the first 10 records from a SQL database table looks like this:

app.get('/posts', (req, res) => {
  Post.findAll()
    .then(posts => {
      res.status(200).json(posts);
    }, err => {
      console.error(err);
      res.status(500).send(err.message);
    });
});

Could you imagine how ugly that gets when you have to implement pagination, filtering, sorting, orβ€”better yetβ€”formatting the response for JSON API?

Also, where does that code live? In what file and folder would I find it? What pattern do you use for organizing this code?

😲Ok ok give me back Rails I'll worry about performance and scaling later. After all, premature optimization is the root of all evil.

Problem.resolve();

Shouldn't there be a better way to do this? Can't I just return a promise or a JavaScript primitive instead of basically using the native Node http server API?

Fortunately ES2015+ has introduced great new features to the JavaScript language, especially when it comes to meta programming.

With Lux your code from before can now look like this:

class PostsController extends Controller {
  index(req, res) {
    return Post.all();
  }
}

Except CRUD actions are taken care of automatically so it would actually look like this:

class PostsController extends Controller {

}

It's about time a Node server framework learned something from client-side JS frameworks.

How?

Installation

npm install -g lux-framework

Creating Your First Project

Use the new command to create your first project.

lux new <app-name>

Running

To run your application use the serve command.

cd <app-name>
lux serve

For more information checkout out the Guides.

Benchmarks

postlight/lux-benchmarks

Contributing

Installation

git clone https://github.com/postlight/lux
cd lux
npm install

Testing

git clone https://github.com/postlight/lux

# Install Lux dependencies
cd lux
npm install

# Install test app dependencies
cd test/test-app
npm install

# Run the test suite
cd ../../
npm test

Useful Links