New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

backend-js

Package Overview
Dependencies
Maintainers
1
Versions
138
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backend-js

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

latest
Source
npmnpm
Version
1.5.10
Version published
Weekly downloads
3
-76.92%
Maintainers
1
Weekly downloads
 
Created
Source

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)

ParameterTypeDescription
pathstringPath to the behaviours directory.
optionsobjectApp configuration options.
options.pathstringPrefix path appended to the beginning of routes.
options.parserstringSupports json, text, raw, or urlencoded. Parses request/response body accordingly.
options.parserOptionsobjectOptions for body-parser.
options.portnumberPort of the server.
options.originsstringAllowed AJAX origins (comma-separated or "*" for all).
options.staticobjectOptions for serving static files.
options.static.routestringVirtual route for static content.
options.static.pathstringPath to directory containing static files.
ReturnsTypeDescription
AppfunctionExpress 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)

ParameterTypeDescription
optionsstring | objectModel name or full configuration object.
options.namestringName of the model.
options.featuresobjectCustom model features passed to the data access layer.
options.queryarrayDefault query represented by QueryExpression.
attributesobjectSchema attributes (String, Number, Date). Supports nested objects or arrays.
pluginsarrayArray of mongoose plugins.
ReturnsTypeDescription
ModelEntityfunctionConstructor 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)

ParameterTypeDescription
operatorsobjectKey-value pairs mapping to database engine operators (used by data access).

var expression = new QueryExpression(options)

ParameterTypeDescription
options.fieldNamestringField name in the model.
options.comparisonOperatorstringComparison operator (=, $ne, etc.).
options.fieldValueanyValue to compare against the field.
options.logicalOperatorstringLogical operator ($and, $or, $not).
options.contextualLevelnumberNesting level of conditions (for grouping).
ReturnsTypeDescription
expressionobjectQuery 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)

ParameterTypeDescription
featuresobjectSpecial model functionalities passed to the data access layer.
ReturnsTypeDescription
entityobjectHolds 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)

ParameterTypeDescription
optionobjectAPI metadata (name, version, path, method, params, returns).
constructorfunctionBusiness 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

Keywords

backend

FAQs

Package last updated on 07 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts