LoopBack is a highly-extensible, open-source Node.js framework that enables developers to create dynamic end-to-end REST APIs with minimal coding.
npx @tessl/cli install tessl/npm-loopback@3.28.0LoopBack is a highly-extensible, open-source Node.js framework that enables developers to create dynamic end-to-end REST APIs with minimal coding. It provides comprehensive data access capabilities for various databases, incorporates model relationships and access controls for complex APIs, and includes built-in authentication, authorization, and middleware capabilities.
npm install loopbackconst loopback = require('loopback');ES6 Modules:
import loopback from 'loopback';const loopback = require('loopback');
const app = loopback();
// Create a simple model
const Book = app.model('Book', {
title: String,
author: String,
isbn: String
});
// Attach model to memory datasource
Book.attachTo(loopback.memory());
// Start the application
app.use(loopback.rest());
app.listen(3000, () => {
console.log('LoopBack server running on port 3000');
});LoopBack is built around several key architectural components:
loopback() function creates Express-based applicationsCore application factory and management functionality for creating LoopBack applications that extend Express with model management capabilities.
/**
* Create a LoopBack application instance
* @param {Object} options - Optional configuration options
* @returns {LoopBackApplication} Express-based LoopBack application
*/
function loopback(options);
/**
* Configure a function as a remote method
* @param {Function} fn - Function to configure
* @param {Object} options - Remote method options
*/
loopback.remoteMethod(fn, options);
/**
* Create a template renderer function
* @param {string} file - Path to template file
* @returns {Function} Template rendering function
*/
loopback.template(file);Comprehensive model creation and configuration system supporting data modeling, validation, relationships, and persistence.
/**
* Create a new model class
* @param {string} name - Model name
* @param {Object} properties - Model properties definition
* @param {Object} options - Model configuration options
* @returns {Function} Model constructor
*/
loopback.createModel(name, properties, options);
/**
* Find an existing model by name
* @param {string} modelName - Name of the model to find
* @returns {Function|null} Model constructor or null if not found
*/
loopback.findModel(modelName);Complete authentication and authorization system with built-in User model, access tokens, roles, and ACL-based permissions.
// Authentication models
loopback.User; // User management and authentication
loopback.AccessToken; // Authentication tokens
loopback.Application; // Application registration
// Authorization models
loopback.ACL; // Access Control Lists
loopback.Role; // User roles
loopback.RoleMapping; // Role assignments
loopback.Scope; // Permission scopesAuthentication & Authorization
Flexible data source management supporting multiple database types and external services through a pluggable connector architecture.
/**
* Create a data source with connector
* @param {string} name - Optional data source name
* @param {Object} options - Data source configuration
* @returns {DataSource} DataSource instance
*/
loopback.createDataSource(name, options);
/**
* Get or create in-memory data source
* @param {string} name - Optional data source name
* @returns {DataSource} Memory data source instance
*/
loopback.memory(name);
// Built-in connectors
loopback.Connector; // Base connector class
loopback.Memory; // Memory connector
loopback.Mail; // Mail connector
loopback.Remote; // Remote connectorExpress-compatible middleware system with LoopBack-specific middleware for REST APIs, authentication, and request processing.
// Core middleware
loopback.rest(); // REST API middleware
loopback.token(options); // Authentication token middleware
loopback.urlNotFound(); // 404 handler middleware
loopback.favicon(); // Favicon middleware
loopback.static(); // Static file middleware/**
* LoopBack Application interface (extends Express)
*/
interface LoopBackApplication {
// Express application methods inherited
// LoopBack-specific methods
model(Model, config); // Attach model to application
dataSource(name, config); // Define data source
enableAuth(options); // Enable authentication
models(); // Get attached models
// ... additional methods in Application Management doc
}
/**
* Data types from loopback-datasource-juggler
*/
class GeoPoint {
constructor(lat, lng);
lat: number;
lng: number;
}
class DateString {
constructor(date);
toString(): string;
}
class ValidationError extends Error {
statusCode: number;
details: ValidationErrorDetail[];
}
// Exported data types
loopback.GeoPoint; // Geographic point type
loopback.DateString; // Date string type
loopback.ValidationError; // Validation error type
/**
* Framework properties
*/
interface LoopBackStatic {
version: string; // Framework version
isBrowser: boolean; // Runtime environment detection
isServer: boolean; // Runtime environment detection
faviconFile: string; // Default favicon path (server only)
}