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 🙏

© 2026 – Pkg Stats / Ryan Hefner

backend-js

v1.5.10

Published

Backend-js is a layer built above expressjs to enable behaviours framework for nodejs applications.

Readme

backend-js Codacy Badge

0_00

Backend-js is a layer built above expressjs and socket.io to enable the Behaviours Framework for Node.js applications.


📦 Installation

npm install backend-js

🚀 Usage

🔧 Backend Initialization

var backend = require('backend-js');
var App = backend.app(__dirname + '/behaviours', {
    path: '/api/v1',
    parser: 'json',
    port: 8383,
    origins: '*'
});

var App = app(path, options)

| Parameter | Type | Description | |-----------------------|---------|--------------------------------------------------------------------------------------------------| | path | string | Path to the behaviours directory. | | options | object | App configuration options. | | options.path | string | Prefix path appended to the beginning of routes. | | options.parser | string | Supports json, text, raw, or urlencoded. Parses request/response body accordingly. | | options.parserOptions | object | Options for body-parser. | | options.port | number | Port of the server. | | options.origins | string | Allowed AJAX origins (comma-separated or "*" for all). | | options.static | object | Options for serving static files. | | options.static.route| string | Virtual route for static content. | | options.static.path | string | Path to directory containing static files. |

| Returns | Type | Description | |---------|----------|--------------------------------------------------------------------------------------| | App | function | Express app instance (API reference). |


🧩 Model Definition

var backend = require('backend-js');
var model = backend.model();
var User = model({
  name: 'User'
}, {
  username: String,
  password: String
});

var ModelEntity = model(options, attributes, plugins)

| Parameter | Type | Description | |-------------------|--------------------|------------------------------------------------------------------------------------------------------------------| | options | string | object | Model name or full configuration object. | | options.name | string | Name of the model. | | options.features| object | Custom model features passed to the data access layer. | | options.query | array | Default query represented by QueryExpression. | | attributes | object | Schema attributes (String, Number, Date). Supports nested objects or arrays. | | plugins | array | Array of mongoose plugins. |

| Returns | Type | Description | |--------------|----------|------------------------------------------| | ModelEntity| function | Constructor for the defined model entity. |


🔍 Query Builder

var QueryExpression = backend.QueryExpression;
var ComparisonOperators = {
    EQUAL: '=',
    NE: '$ne'
};
var LogicalOperators = {
    AND: '$and',
    OR: '$or',
    NOT: '$not'
};
backend.setComparisonOperators(ComparisonOperators);
backend.setLogicalOperators(LogicalOperators);

var query = [
  new QueryExpression({
    fieldName: 'username',
    comparisonOperator: ComparisonOperators.EQUAL,
    fieldValue: 'name'
  }),
  new QueryExpression({
    fieldName: 'password',
    comparisonOperator: ComparisonOperators.EQUAL,
    fieldValue: 'pass',
    logicalOperator: LogicalOperators.AND,
    contextualLevel: 0
  })
];

setComparisonOperators(operators) / setLogicalOperators(operators)

| Parameter | Type | Description | |-----------|--------|-----------------------------------------------------------------------------| | operators | object | Key-value pairs mapping to database engine operators (used by data access). |

var expression = new QueryExpression(options)

| Parameter | Type | Description | |-----------------------|--------|-------------------------------------------------------------------------------------------------| | options.fieldName | string | Field name in the model. | | options.comparisonOperator | string | Comparison operator (=, $ne, etc.). | | options.fieldValue | any | Value to compare against the field. | | options.logicalOperator | string | Logical operator ($and, $or, $not). | | options.contextualLevel | number | Nesting level of conditions (for grouping). |

| Returns | Type | Description | |-------------|--------|-----------------------------------------------------------------------------| | expression| object | Query expression object used in queries. |


🧱 Entity API

var ModelEntity = backend.ModelEntity;
var entity = new ModelEntity({});
var model = entity.getObjectConstructor();
var schema = entity.getObjectAttributes();
var features = entity.getObjectFeatures();
var query = entity.getObjectQuery();

var entity = new ModelEntity(features)

| Parameter | Type | Description | |---------------|--------|------------------------------------------------------------------------------| | features | object | Special model functionalities passed to the data access layer.|

| Returns | Type | Description | |--------------|--------|------------------------------------| | entity | object | Holds model metadata and schema. |

Entity Methods:

  • getObjectConstructor() – returns model constructor
  • getObjectAttributes() – returns schema fields
  • getObjectFeatures() – returns model features
  • getObjectQuery() – returns default query array

⚙️ Behaviour (API Unit)

var getUsers = behaviour({
  name: 'GetUsers',
  version: '1',
  path: '/users',
  method: 'GET'
}, function(init) {
  return function() {
    var self = init.apply(this, arguments).self();
    self.begin('Query', function(key, businessController, operation) {
        operation
          .entity(new User())
          .append(true)
          .apply();
    });
  };
});

var Behavior = behaviour(option, constructor)

| Parameter | Type | Description | |---------------|----------|-----------------------------------------------------------------------------| | option | object | API metadata (name, version, path, method, params, returns). | | constructor | function | Business logic with database or response mapping functionality. |


🧬 Data Access

Define your own data access layer like below:

var backend = require('backend-js');

var ModelController = function () {
    self.removeObjects = function (queryExprs, entity, callback) {
        // do remove
    };
    self.addObjects = function (objsAttributes, entity, callback) {
        // do add new
    };
    self.getObjects = function (queryExprs, entity, callback) {
        // do select
    };
    self.save = function (callback, oldSession) {
        // do save
    };
};

ModelController.defineEntity = function (name, attributes) {
    // define entity
    return entity;
};

ModelController.prototype.constructor = ModelController;

backend.setModelController(new ModelController());

🚀 Starter Project

Explore the official starter to learn Backend-JS with examples:

🔗 https://github.com/QuaNode/BeamJS-Start


📄 License