SWK Magdeburg - Björn Strobach - Dezember 2017
“LoopBack is a highly-extensible, open-source Node.js framework”
Quickly create dynamic end-to-end REST APIs.
Connect devices and browsers to data and services.
Use Android, iOS, and AngularJS SDKs to easily create client apps.
Add-on components for file management, 3rd-party login, and OAuth2.
Runs on-premises or in the cloud
Asynchronous event driven JavaScript runtime
Built on Chrome's V8 JavaScript engine
Designed to build scalable network applications
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Install Node.js (Better: use a Node version manager)
Save above content to a file (e.g.
app.js
) and run:
$ node app.js
Visit 127.0.0.1:3000
Minimal and flexible Node.js framework
With a myriad of HTTP utility methods and middleware
Provides a thin layer of fundamental web application features, without obscuring Node.js features
const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(3000, () => console.log('Example app listening on port 3000!'))
Install Node.js (Better: use a Node version manager)
Save above content to a file (e.g.
app.js
) and run:
$ npm i express && node app.js
Visit 127.0.0.1:3000
Quickly create an application skeleton
$ npm i [-g] express-generator
$ ./node_modules/.bin/express myApp
.
├── app.js
├── bin
│ └── www
├── package.json
├── public
│ ├── images
│ ├── javascripts
│ └── stylesheets
│ └── style.css
├── routes
│ ├── index.js
│ └── users.js
└── views
├── error.jade
├── index.jade
└── layout.jade
7 directories, 9 files
Install dependencies
$ cd myApp && npm i
Run the app
$ DEBUG=myapp:* npm start
A set of Node.js modules
Can be used independently or together
Models
Application logic
Datasource and connectors
LoopBack components
Represent backend data sources (such as databases or services like REST, SOAP)
JavaScript objects with Node and Rest-APIs
One base model object, with hooks and data validation methods
Connected to a data source Every model comes with a predefined REST API (full set of CRUD)
Every LoopBack application comes with predefined built-in models
User, Role, and Application
So you don't have to create these common models from scratch
Define own models specific to the application
One can extend the built-in models
Stored in model definition JSON file
One can define relations between models
E.g. BelongsTo, HasMany, HasAndBelongsToMany, and more
Operation | REST | LoopBack model method | Corresponding SQL Operation |
---|---|---|---|
Create | PUT|POST /modelname |
create() | INSERT |
Read (retrieve) | GET /modelName?filter=... |
find() | SELECT |
Update (modify) | PUT /modelName |
updateAll() | UPDATE |
Delete (destroy) | DELETE /modelName/modelID |
destroyByID() | DELETE |
Remote methods (custom REST endpoints)
Remote hooks triggered by remote methods
Operation hooks triggered by CRUD
Boot scripts
Middleware (Express)
Push notifications
Storage components
Third party login
Synchronization
OAuth2
Install Node.js (Better: use a Node version manager)
Install LoopBack CLI tool
$ npm i -g loopback-cli
Run the LoopBack application generator
$ lb
GitHub: @bstrobach
Twitter: @bstrobach
Xing: http://xing.to/bstrobach