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

sand

v1.8.1

Published

A framework based on grains (modules)

Downloads

17

Readme

Sand.js

Build Status

Sand is a lightweight, all-purpose Javascript application framework. Sand provides a simple, yet robust, application lifecycle and many pluggable clients and libraries.

Lifecycle features include:

Initialization/Start/Shutdown hooks

Execute custom code before the app starts, when the app starts, and when the app shuts down.

Automatic config loading by environment

When Sand initializes all its plugins, each plugin will automatically load its proper configuration based on the application execution environment specified in process.env.NODE_ENV. Some common plugins include MySQL, Memcache, ElasticSearch, etc. If your app doesn't use execution environments, don't worry! There's a default config section for that.

Unique Execution Context

Sand provides a generic, unique "per request" execution context for any job. "per request" may be understood in the same way as a typical web application request that has it's own execution environment.

Simple, Robust Plugin system

Sand provides a simple Plugin API. All plugins are called Grains. A grain provides a simple API of init, start, and shutdown which the main Sand application invokes at the appropriate lifecycle point.

Web Applications

One of Sand's strongest features is it's fully featured, all-purpose Web Application Server provided in sand-http.

Sand HTTP provides:

  • Regular Expression based routing
  • Request Middleware à la Express.js
  • MVC support
  • Model querying (M from MVC) with Sand MySQL. MySQL is the most commonly used Model library, but any ORM can be adapted to be used in Sand with Sand's easy plugin system.
  • View Rendering (V from MVC) with the template language of your choice (EJS, Jade/Pug, etc.)
  • Route mappings to Controller/Actions (C from MVC)
  • Any ORM may be made pluggable using Sand's plugin system.

The simplest Sand application

You can create ANY kind of Node.js application, script, or service using Sand.

The simplest Sand application is shown below.

let Sand = require('sand');
let app = new Sand();
app.start(function () {
  console.log('Hello, World!');
});

The require('sand') loads the Sand Application class.

To create a new application, simply instantiate the Sand Application class.

Only one instance of a Sand application is allowed. When the Application has been instantiated, the global.sand variable will be set with that instance. All modules and application files will be able to reference the main application instance by global.sand or just sand.

Passing a callback to Sand#start() will ensure that the code in your callback gets executed after the application has started.

Sand Grains

A Sand "grain" is a plugin for the Sand.js Application.

How grains work

  • A grain is a node module that exports a class extending SandGrain found in the sand-grain module.
  • The class implements member functions init, start, and shutdown which are invoked by the Sand Application during its lifecycle. These hooks load and dispose of any resources that the plugin provides to the application.
  • In the init() hook, the grain loads it's config and sets it on the grain instance.
  • During the init stage of the application, the Sand application creates a new instance of the grain, and sets it on the application instance. This means that the grain instance may be accessed from any file in the application using the syntax sand.customGrain.
  • Every grain documents it's
    • Configuration file name (i.e. config/custom-grain.js)
    • Configuration options (i.e. { key1: "value1", ... })
    • Global reference (i.e. sand.customGrain)
    • If a "grain" doesn't document these, then bug the "grain" developer to document them or look at the grain source.
  • Sand grains may be loaded into an application using app.use(). Grains may not be loaded after app.start() has been called.

How to use grains

Ensure that the grain is installed.

let CustomGrain = require('sand-custom-grain');
let Sand = require('sand');

let app = new Sand() // initialize the application
  .use(CustomGrain); // load the sand grain 

app.start(function () { // start the application
  console.log('Hello, World!');
  console.log(sand.customGrain); // this should output the instance of the sand grain
});

The Sand#use() function loads a Sand Grain into the application.

Learn More

Check out the sand-http readme for an example of how Sand.js web applications work.