npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tilt

v0.2.0

Published

Minimalist, ES6 based, developer-friendly web framework for node.

Downloads

95

Readme

tilt Build Status

wip

Minimalist, ES6 based, developer-friendly web framework for node.

Inspired by Play Framework and Sails / Trails, Tilt aims to be a lightweight framework to quickly develop new nodejs application using a set of common tools that works well together.

  • Routers / Controllers tilt-router Standard ES6 Class defines the mapping between URLs pattern and request handlers
  • Views tilt-react-views Views are built using React Components through res.render() method
  • Models Models are ES6 Class that extends tilt.Model to offer a thin abstraction on top of Sequelize.
  • Modular architecture Glob patterns are used to load Controllers, Models and configure directories. Supports multiple Views, assets and static directories allowing any kind of file structure.
  • Asset pipeline tilt-assets implements a basic Asset pipeline for any /assets/*.{js,css} URLs. JS files are compiled down to ES6 using Browserify with Babelify transform. CSS files are processed by PostCSS and autoprefixer plugin.

wip

wip: todo

🐰 Development documentation

git clone https://github.com/mklabs/tilt.git
cd tilt

# Run babel / test on source changes
npm run watch

# Start example app
npm start
  • npm start to start the server. It'll run babel once before and use nodemon to restart the server if needed.
  • npm run watch will recompile and relaunch the tests.

The lib/ folder is where sources are, the src/ folder are where generated sources are.

Example

var path = require('path');
var tilt = require('tilt');

var app = tilt();

app
  // Controllers, default: app/controllers/*
  .controllers(path.join(__dirname, 'app/controllers/*'))

  // Same for models
  .models(path.join(__dirname, 'app/models/*'))

  // Views directories, default: app/views/ (must end with a "/")
  .views(path.join(__dirname, 'app/views/'))


  // Static / public directories, default: app/public/
  .static(path.join(__dirname, 'app/public/'))

  // Assets directories, default: disabled
  .assets(path.join(__dirname, 'app/assets/'))

  // Custom middlewares
  .use(require('morgan')('dev'));

  // Start the server
  .start(function(err) {
    if (err) throw err;
    console.log('Server started');
  });

Routers / Controllers

app/controllers/main.js

Controllers (or Routers) are standard ES6 Class that inherits from tilt.Controller.

They implement a routes hash that defines the mapping between URLs pattern and class methods / request handlers.

req and res are standard node HTTP request and response.

var Controller = require('tilt').Controller;

class Router extends Controller {
  get routes() {
    return {
      '/': 'index'
    };
  }

  index(req, res) {
    return res.render('index', { name: 'Title!' });
  }
}

module.exports = Router;

Views

app/views/index.jsx

res.render(filename, { ... }) is used to render React components and serve the resulting HTML.

React JSX views are automatically transpiled by Babel when the framework requires them.

import React from 'react';

class HelloMessage extends React.Component {
  render() {
    return (<div>Hello {this.props.name}</div>);
  }
}

module.exports = HelloMessage;

Models

app/models/user.js

Models inherits from tilt.Model to provide a thin abstraction on top of Sequelize.

Both attributes and options getters maps the sequelize.define('name', {attributes}, {options}) equivalent.

  • attributes Specifiy the Model schema (Model Definition)
  • options Specifiy the Model options

Most of Sequelize Model API is available on tilt.Model instances.

var tilt = require('tilt');

class User extends tilt.Model {
  get attributes() {
    return {
      username: tilt.Sequelize.STRING,
      birthday: tilt.Sequelize.DATE
    };
  }

  get options() {}
}

module.exports = User;

Then used like so:

create(req, res, next) {
  var user = new User({
    username: 'foobar',
    birthday: new Date()
  }, this.db);

  user.save()
    .catch(next)
    .then(() => {
      res.end('User saved');
    });
}

API

Tilt

HTTP server

Renders 404 html.

request(this.app.server)
  .get('/blah')
  .expect('Content-Type', 'text/html')
  .expect(404)
  .end(done);

Renders homepage.

request(this.app.server)
  .get('/')
  .expect('Content-Type', 'text/html')
  .expect(/Bonjour Title/)
  .end(done);

Renders /home.

request(this.app.server)
  .get('/home')
  .expect(/Response from/)
  .end(done);

HTTP server with module based architecture

Renders 404 html.

request(this.app.server)
  .get('/blah')
  .expect('Content-Type', 'text/html')
  .expect(404)
  .end(done);

Renders homepage.

request(this.app.server)
  .get('/')
  .expect('Content-Type', 'text/html')
  .expect(/Hello Bob/)
  .end(done);

Renders /profile.

request(this.app.server)
  .get('/profile')
  .expect(/Response from profile module/)
  .end(done);

Renders /profile/template.

request(this.app.server)
  .get('/profile/template')
  .expect(/Response from profile module using a React view/)
  .end(done);

Assets

HTTP /assets/

Renders /assets/main.js.

request(this.app.server)
  .get('/assets/main.js')
  .expect('Content-Type', 'application/javascript')
  .expect(/classCallCheck/)
  .expect(/return App/)
  .end(done);

Renders /assets/main.css.

request(this.app.server)
  .get('/assets/main.css')
  .expect('Content-Type', 'text/css')
  .expect(/display: flex/)
  .expect(/display: -webkit-box/)
  .end(done);

tilt.Model

Defines a sequelize instance.

var User = class extends tilt.Model {
  get attributes() {
    return {
      username: tilt.Sequelize.STRING,
      birthday: tilt.Sequelize.DATE
    };
  }
  get options() {}
}
var user = new User({
  username: 'John Doe',
  birthday: new Date()
}, this.app.db);
assert.ok(user.sequelize);
// Sequelize API
assert.equal(typeof user.find, 'function');
assert.equal(typeof user.findById, 'function');
``