or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

application.mdauth.mddatasources.mdindex.mdmiddleware.mdmodels.md

index.mddocs/

0

# LoopBack

1

2

LoopBack 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.

3

4

## Package Information

5

6

- **Package Name**: loopback

7

- **Package Type**: npm

8

- **Language**: JavaScript (Node.js)

9

- **Installation**: `npm install loopback`

10

11

## Core Imports

12

13

```javascript

14

const loopback = require('loopback');

15

```

16

17

ES6 Modules:

18

19

```javascript

20

import loopback from 'loopback';

21

```

22

23

## Basic Usage

24

25

```javascript

26

const loopback = require('loopback');

27

const app = loopback();

28

29

// Create a simple model

30

const Book = app.model('Book', {

31

title: String,

32

author: String,

33

isbn: String

34

});

35

36

// Attach model to memory datasource

37

Book.attachTo(loopback.memory());

38

39

// Start the application

40

app.use(loopback.rest());

41

app.listen(3000, () => {

42

console.log('LoopBack server running on port 3000');

43

});

44

```

45

46

## Architecture

47

48

LoopBack is built around several key architectural components:

49

50

- **Application Factory**: The main `loopback()` function creates Express-based applications

51

- **Model System**: Base Model and PersistedModel classes provide data modeling and persistence

52

- **Registry System**: Central registry for managing models, datasources, and connectors

53

- **Built-in Models**: Pre-built models for authentication (User, AccessToken) and authorization (ACL, Role)

54

- **Connector Architecture**: Pluggable connectors for different data sources and services

55

- **Middleware System**: Express-compatible middleware with LoopBack-specific enhancements

56

- **Access Control**: Comprehensive ACL system for fine-grained permissions

57

58

## Capabilities

59

60

### Application Creation and Management

61

62

Core application factory and management functionality for creating LoopBack applications that extend Express with model management capabilities.

63

64

```javascript { .api }

65

/**

66

* Create a LoopBack application instance

67

* @param {Object} options - Optional configuration options

68

* @returns {LoopBackApplication} Express-based LoopBack application

69

*/

70

function loopback(options);

71

72

/**

73

* Configure a function as a remote method

74

* @param {Function} fn - Function to configure

75

* @param {Object} options - Remote method options

76

*/

77

loopback.remoteMethod(fn, options);

78

79

/**

80

* Create a template renderer function

81

* @param {string} file - Path to template file

82

* @returns {Function} Template rendering function

83

*/

84

loopback.template(file);

85

```

86

87

[Application Management](./application.md)

88

89

### Model Definition and Management

90

91

Comprehensive model creation and configuration system supporting data modeling, validation, relationships, and persistence.

92

93

```javascript { .api }

94

/**

95

* Create a new model class

96

* @param {string} name - Model name

97

* @param {Object} properties - Model properties definition

98

* @param {Object} options - Model configuration options

99

* @returns {Function} Model constructor

100

*/

101

loopback.createModel(name, properties, options);

102

103

/**

104

* Find an existing model by name

105

* @param {string} modelName - Name of the model to find

106

* @returns {Function|null} Model constructor or null if not found

107

*/

108

loopback.findModel(modelName);

109

```

110

111

[Model System](./models.md)

112

113

### Built-in Authentication and Authorization

114

115

Complete authentication and authorization system with built-in User model, access tokens, roles, and ACL-based permissions.

116

117

```javascript { .api }

118

// Authentication models

119

loopback.User; // User management and authentication

120

loopback.AccessToken; // Authentication tokens

121

loopback.Application; // Application registration

122

123

// Authorization models

124

loopback.ACL; // Access Control Lists

125

loopback.Role; // User roles

126

loopback.RoleMapping; // Role assignments

127

loopback.Scope; // Permission scopes

128

```

129

130

[Authentication & Authorization](./auth.md)

131

132

### Data Source and Connector Management

133

134

Flexible data source management supporting multiple database types and external services through a pluggable connector architecture.

135

136

```javascript { .api }

137

/**

138

* Create a data source with connector

139

* @param {string} name - Optional data source name

140

* @param {Object} options - Data source configuration

141

* @returns {DataSource} DataSource instance

142

*/

143

loopback.createDataSource(name, options);

144

145

/**

146

* Get or create in-memory data source

147

* @param {string} name - Optional data source name

148

* @returns {DataSource} Memory data source instance

149

*/

150

loopback.memory(name);

151

152

// Built-in connectors

153

loopback.Connector; // Base connector class

154

loopback.Memory; // Memory connector

155

loopback.Mail; // Mail connector

156

loopback.Remote; // Remote connector

157

```

158

159

[Data Sources & Connectors](./datasources.md)

160

161

### Middleware and Request Processing

162

163

Express-compatible middleware system with LoopBack-specific middleware for REST APIs, authentication, and request processing.

164

165

```javascript { .api }

166

// Core middleware

167

loopback.rest(); // REST API middleware

168

loopback.token(options); // Authentication token middleware

169

loopback.urlNotFound(); // 404 handler middleware

170

loopback.favicon(); // Favicon middleware

171

loopback.static(); // Static file middleware

172

```

173

174

[Middleware System](./middleware.md)

175

176

## Core Types

177

178

```javascript { .api }

179

/**

180

* LoopBack Application interface (extends Express)

181

*/

182

interface LoopBackApplication {

183

// Express application methods inherited

184

185

// LoopBack-specific methods

186

model(Model, config); // Attach model to application

187

dataSource(name, config); // Define data source

188

enableAuth(options); // Enable authentication

189

models(); // Get attached models

190

// ... additional methods in Application Management doc

191

}

192

193

/**

194

* Data types from loopback-datasource-juggler

195

*/

196

class GeoPoint {

197

constructor(lat, lng);

198

lat: number;

199

lng: number;

200

}

201

202

class DateString {

203

constructor(date);

204

toString(): string;

205

}

206

207

class ValidationError extends Error {

208

statusCode: number;

209

details: ValidationErrorDetail[];

210

}

211

212

// Exported data types

213

loopback.GeoPoint; // Geographic point type

214

loopback.DateString; // Date string type

215

loopback.ValidationError; // Validation error type

216

217

/**

218

* Framework properties

219

*/

220

interface LoopBackStatic {

221

version: string; // Framework version

222

isBrowser: boolean; // Runtime environment detection

223

isServer: boolean; // Runtime environment detection

224

faviconFile: string; // Default favicon path (server only)

225

}

226

```