• Stars
    star
    571
  • Rank 78,127 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build scalable, Node.js-powered REST JSON APIs with almost no code.

Lux

CircleCI branch AppVeyor Codecov branch David npm Gitter

Lux by Postlight is an 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. Read about it in this handy introduction.

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.

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

Contribution

See CONTRIBUTING.md.

Useful Links


πŸ”¬ A Labs project from your friends at Postlight. Happy coding!

More Repositories

1

parser

πŸ“œ Extract meaningful content from the chaos of a web page
JavaScript
5,062
star
2

headless-wp-starter

πŸ”ͺ WordPress + React Starter Kit: Spin up a WordPress-powered React app in one step
JavaScript
4,367
star
3

awesome-cms

πŸ“š A collection of open and closed source Content Management Systems (CMS) for your perusal.
2,711
star
4

serverless-typescript-starter

πŸ—„πŸ™…β€β™€οΈ Deploy your next serverless JavaScript function in seconds
TypeScript
713
star
5

liftoff

πŸš€ Liftoff is a flexible static-site generator that pulls content from Airtable
JavaScript
343
star
6

parser-api

πŸš€ A drop-in replacement for the Postlight Parser API.
JavaScript
280
star
7

trimmings

🌲 Get back to HTML.
JavaScript
221
star
8

nodejs-typescript-kit

πŸ›  Node.js + TypeScript with all the goods: A zero-to-coding starter kit with all the modern tooling baked in.
JavaScript
107
star
9

account

πŸ“šοΈ βž• πŸ”’ Tell little stories with numbers
JavaScript
107
star
10

cloudflare-worker-app-kit

☁✨ A handy set of tools for creating a Cloudflare Worker app.
JavaScript
85
star
11

glide

☁ 🎑Modernize Salesforce API access with GraphQL
TypeScript
77
star
12

react-google-sheet-to-chart

πŸ“Š React component that renders Google Sheets as attractive charts with minimum effort
JavaScript
63
star
13

wp-callisto-migrator

🌐 πŸ‘‰ πŸ“‹ Migrate any content to WordPress in a few clicks
PHP
33
star
14

robo-chart-web

πŸ“Š Transform Google sheets to pretty charts!
JavaScript
27
star
15

lorem-ipsum-generator-generator

🎰 Generate a lorem ipsum generator site using Mercury Web Parser
HTML
26
star
16

secretmsg

πŸ•΅ Encrypt messages for easy sharing
TypeScript
23
star
17

generate-awesome

πŸ–¨ A command-line tool for generating Awesome Lists from a set of data files.
JavaScript
22
star
18

mercury-rs

The official Rust client for the Mercury Parser
Rust
16
star
19

ci-failed-test-reporter

πŸ“ A tool for posting failing test results to GitHub PRs
JavaScript
10
star
20

hubot-spotify-playlist

Allows the ability to add/remove/findTracks to a Spotify Playlist.
CoffeeScript
7
star
21

docker-lux

The official Docker image for Lux 🐳 πŸ”†
JavaScript
7
star
22

parser-api-express

Postlight Parser API express app
JavaScript
6
star
23

babel-preset-lux

A babel preset containing all of the plugins required by Lux.
JavaScript
6
star
24

lux-benchmarks

JavaScript
5
star
25

rollup-plugin-lux

A Rollup plugin for bundling Lux applications.
JavaScript
3
star
26

lux-rfcs

RFCs for changes to Lux
2
star
27

use-search-params

A simple react hook for query params.
TypeScript
2
star
28

seasons

πŸŒ” Calculates the astronomical season for a given date or year
TypeScript
1
star
29

hubot-pingboard

πŸ‘₯ A hubot script for interacting with Pingboard.com.
CoffeeScript
1
star