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

americano

v0.4.5

Published

Wrapper for Express that makes its configuration clean and easy.

Downloads

101

Readme

Americano

ExpressJS is an awesome tool to build small web application. But once you start using it, you discover that writing the configuration and the routes often leads to ugly code. To solve that, Americano acts as a wrapper around Express and make it more opinionated about how to write routes and configuration. See in the following how it make things cleaner.

When to use Americano?

Americano is:

  • a tool to quickstart small web applications or web modules.
  • oriented to build single page-app and REST API.

Americano is not:

  • a full-featured framework for making big web applications.

NB: Americano inherits all the ExpressJS features

Getting started

Binary

There is a binary provided with Americano to start quickly your project:

Install

npm install americano -g

Usage

americano blog

Output

create: blog
create: blog/package.json
create: blog/server.js
create: blog/README.md
create: blog/client/public
create: blog/server/models
create: blog/server/controllers
create: blog/server/controllers/routes.js
create: blog/server/controllers/index.js
create: blog/server/config.js

install dependencies:
$ cd blog && npm install

Run your application:
$ npm start

Coffeescript Usage

americano --coffee blog

Handmade

To write an Americano application you need to add it as a dependency of your package.json file.

npm install americano --save

Then you must to create your main file:

// ./server.js
var americano = require('americano');

var port = process.env.PORT || 3000;
americano.start({name: 'yourapp', port: port}, function(err, app, server) {
  // Do something when everything is properly started.
});

Configuration

Americano requires a config file located at the root of your project, let's add it:

// ./server/config.js
var americano = require('americano');

module.exports = {
  common: { 
    use: [
      americano.bodyParser(),
      americano.methodOverride(),
      americano.static(__dirname + '/../client/public', {
        maxAge: 86400000
      })
    ]
    useAfter: [
      americano.errorHandler({
        dumpExceptions: true,
        showStack: true
      })
    ]
  },
  development: {
    use: [
      americano.logger('dev')
    ],
    set: {
      debug: 'on'
    }
  },
  production: [
    americano.logger('short')
  ]
};

Routes

Once configuration is done, Americano will ask for your routes to be described in a single file following this syntax:

// ./server/controllers/routes.coffee
var posts = require('./posts');
var comments = require('./comments');

module.exports = {
  'posts': {
    get: posts.all,
    post: posts.create
  },
  'posts/:id': {
    get: posts.show,
    put: posts.modify,
    del: [posts.verifyToken, posts.destroy]
  },
  'posts/:id/comments': {
    get: comments.fromPost
  },
  'comments': {
    get: comments.all
  }
};

Controllers

Your controllers can be written as usual, they are ExpressJS controlllers.

Final thoughts

You're done! Just run node server.js and you have your configured Express web server up and running!

By the way this is how your single-page app looks like with Americano:

your-blog/
    server.js
    server/
        config.js
        controllers/
            routes.js
            posts.js
            comments.js
        models/
            post.js
            comment.js
    client/
        ... front-end stuff ...

Plugins

Americano allows to use plugins that shares its philosophy of making cleaner and more straightforward things.

Actually there is only one plugin, feel free to add yours:

What about contributions?

Here is what I would like to do next:

  • make a plugin for socket-io
  • make a plugin for mongoose
  • make a plugin for sqlite
  • make a plugin for cozy-realtime-adapter

I didn't start any development yet, so you're welcome to participate!