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 🙏

© 2025 – Pkg Stats / Ryan Hefner

little-bear

v0.0.6

Published

Node.js web framework.

Downloads

14

Readme

little-bear

Build Status

little-bear is a web framework that base on express.

Table of contents

Quick Start

Create a server directory

A simple server looks like:

server/
├── theme.css
├── app.js
├── index.html
└── app.sv.js

app.sv.js:

exports.def = function() {
    var path = require('path');

    this.get('/', function(req, res, next) {
        res.sendFile(path.join(__dirname, 'index.html'));
    });
};

index.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Hello, world!</title>
    <link rel="stylesheet" href="./theme.css">
</head>
<body>
    <h1>Hello, world!</h1>
    <script src="./app.js"></script>
</body>
</html>

Run LittleBear app

Assuming that the project directory looks like:

project/
├── server/
└── app.js

app.js:

var path = require('path');
var LittleBear = require('little-bear');

var bear = new LittleBear({
    root: path.join(__dirname, 'server')
});
bear.run(3000);

Server Directory

Static Files Middleware

You could use LittleBear.static middleware to serve static files:

exports.def = function() {
    var LittleBear = require('little-bear');
    this.use(LittleBear.static(__dirname));
};

In static directory, all files are public unless:

  1. node_modules/ directory
  2. has prefix ., such as .git/, .gitignore
  3. has prefix _, such as _views/
  4. has suffix .sv.js or .mod.js

Nodejs Server Script File

The file that has suffix .sv.js or .mod.js will be treated as server script file, LittleBear will require and run it.

Modularization

A server script file that has suffix .mod.js is a module, it must export name and def:

exports.name = 'models.Article';

exports.def = function() {
    var Article = {};
    Article.find = function() {/*...*/};
    return Article;
};

If a module has dependencies, it should export deps:

exports.name = 'someArticles';

exports.deps = {
    Article: 'models.Article'
};

exports.def = function(mods) {
    return mods.Article.find();
};

Routes

LittleBear will set the routes automatically according to the file name.
You could define routes in server script file that has suffix .sv.js. In these files, the context of def function is an instance of express.Router or express.Application.

server/
├── api/
│   ├── articles.sv.js
│   └── users.sv.js
├── blog/
│   └── index.sv.js
├── about.sv.js
└── index.sv.js

index.sv.js:

exports.def = function() {
    // GET /
    this.get('/', function(req, res, next) {
        res.send('home');
    });
};

about.sv.js:

exports.def = function() {
    // GET /about
    this.get('/', function(req, res, next) {
        res.send('about');
    });
};

api/articles.sv.js:

exports.deps = {
    Article: 'models.Article'
};

exports.def = function(mods) {
    // GET /api/articles
    this.get('/', function(req, res, next) {
        res.json(mods.Article.find());
    });

    // GET /api/articles/:id
    this.get('/:id', function(req, res, next) {
        res.json({
            id: req.params.id
        });
    });
};

blog/index.sv.js:

exports.def = function() {
    // GET /blog
    this.get('/', function(req, res, next) {
        res.send('blog');
    });
};

app.sv.js

If a directory has app.sv.js file, the directory will be mount as a sub app.
The context of def function is an instance of express.Application.

var LittleBear = require('little-bear');
exports.def = function(mods, routes) {
    this.engine('jade', require('jade').__express);
    this.set('views', rootPath);
    this.set('view engine', 'jade');

    routes(); // init routes, it must be called

    this.use(LittleBear.static(__dirname));

    this.use(function(err, req, res, next) {
        console.error(err.stack || err);
        res.sendStatus(500);
    });
};

API Reference

new LittleBear(opts)

Arguments

  • opts: {Object} - Initial options.
    • root: {String} - The absolute path of server directory.

Example

var bear = new LittleBear({
    root: path.join(__dirname, 'server')
});

LittleBear.prototype.init()

Only init modules and routes.

Return

  • {Promise}

Example

var bear = new LittleBear(opts);
bear.init().then(function(app) {
    // app is an instance of express.Application
}).catch(console.error);

LittleBear.prototype.run(port)

Init and run LittleBear app.

Arguments

  • port: {Number} - The port number that LittleBear app will listen on.

Example

var bear = new LittleBear(opts);
bear.run(3000);

LittleBear.static(path)

Return a static server middleware.

Arguments

  • path: {String} - The absolute path of static directory.

Example

In app.sv.js:

var LittleBear = require('little-bear');
exports.def = function(mods, routes) {
    routes();
    this.use(LittleBear.static(__dirname));
};

Features

  • Test support

License

MIT