training.shoppinpal.com
  • Introduction
  • 1. The Ideal Workspace
    • The Perfect Machine
      • For Biz Team
      • For Developers
      • For Designers
    • Setup a machine in the cloud
      • Solution
      • Setup box on Azure
        • Create a machine on Azure
        • Test drive your remote machine
        • Setup Dropbox On Azure
      • Setup box on DigitalOcean
        • Setup UI
        • Shared FileSystem
          • Dropbox
            • Use locally developed node modules in another project
          • sshfs
        • Long Running Sessions
      • Feedback
  • 2. Learning Git
    • Static Code Analysis
  • 3. The Backend
    • Use Containers
    • Setup a loopback project
    • Lockdown
    • Build a better mousetrap
    • The abyss stares back
    • Built-in models
    • Extending built-in models
    • Understanding UserModel
    • Boot Scripts
    • Promises
    • Find roles for current user
    • Loopback Console
    • Current User
  • 4. Multi-tenancy With Loopback
    • What is Multi-Tenancy
    • Architecting with Loopback
    • Define scope for Roles
    • Role Resolvers
    • Access Control For Tenants
    • Better Programming with multi-tenancy
  • 5. The Frontend
    • The Browser
    • Unit Testing
      • Motivation behind this blog
      • How to write a test
      • Karma and Jasmin
      • Writing Tests
    • End-2-End Testing
    • Angular 1.x
    • Angular 2
      • Testing
  • 6. ElasticSearch
    • Better Search with NGram
    • NGram with Elasticsearch
    • Fun with Path Hierarchy Tokenizer
    • Working with Mappings and Analyzers
  • 7. Promises
    • What are Promises
    • Promise Implementations
    • Nuances
    • What should we use
  • 8. Learning Docker
    • Docker Swarm
  • 9. Queues & Workers
    • PHP workers in AWS EBS
    • NodeJS workers in AWS EBS
      • SQS Daemon by AWS
      • SQS Daemon in NodeJS
      • SQS polling by worker
    • Gearman
  • 10. Docker
    • Capabilities
  • Appendix
    • Bug in WebStorm deployments
    • The Perfect Terminal
    • Scalable App Deployment with AWS
    • Chrome Tips & Tricks
    • Host your own Gitbook
    • Gitbook Tips & Tricks
    • How to handle support incidents
    • Dev Resources
    • Debug e2e Tests on CircleCI
    • Logging
    • Authentication Principles
    • Mac
    • nvm
    • Unify testing with npm
      • Debugging Mocha
    • Sequence Diagrams
    • Project Sync via IDE
      • SFTP with WebStorm
      • SFTP with Visual Studio
    • Soft Linking
    • NodeJS Profiling
      • How to find node.js performance optimization killers
    • Setup Packer on Azure
Powered by GitBook
On this page
  1. 3. The Backend

Loopback Console

PreviousFind roles for current userNextCurrent User

Last updated 7 years ago

Using the API Explorer in the browser is all right but if you're looking for something a bit slicker then the can be your goto tool.

As of this writing, it is developed and maintained by , his GitHub handle is doublemarked and you can to express your gratitude if you like, in a gitter.im chat room, if you feel so inclined.

loopback-console has many advanced uses and it is even used in production alongside deployed loopback solutions for some very clever reasons that I do not fully understand ... so we will stick to one of its simpler uses: command line interface (CLI) for exploring the API.

Lets get cracking:

a) Install it in your loopback project:

$ cd ~/workspace/loopback-zero-to-hero
$ npm install --save loopback-console
loopback-console@0.1.0 node_modules/loopback-console
├── repl.history@0.1.3
├── app-root-path@1.0.0
└── lodash@3.10.0

b) Set it up for easy access. Update your file. FROM:

  "scripts": {
    "pretest": "jshint ."
  },

TO:

  "scripts": {
    "console": "$(npm bin)/loopback-console .",
    "pretest": "jshint ."
  },

c) Take it for a spin:

c.1) npm run console

c.2) Let's try to list all users: var allUsers = UserModel.find({include:'roles'},cb)

c.3) Results will be something like:

loopback > [ { username: 'admin',
    password: '$2a$10$R.LFPzD7Ov3KZOyw9unS2.drCAbBI7IEVLCK.qX7H/28oKhVME0vq',
    email: 'admin@admin.com',
    firstName: 'Admin',
    lastName: 'User',
    id: 1,
    roles: [ [Object] ] },
  { username: 'user',
    password: '$2a$10$ZXi51B8JH2Su48XA5P/Y7eUrgqiUbnvfyBiJa1dTFlupeKct9X9ei',
    email: 'user@user.com',
    firstName: 'Guest',
    lastName: 'User',
    id: 2,
    roles: [ [Object] ] } ]

press ctrl+c once to kill this command so that you may enter the next one.

c.4) To unpack the roles: [ [Object] ] piece, let's look at a specific result from the array: result[0]

loopback > result[0]
{ username: 'admin',
  password: '$2a$10$R.LFPzD7Ov3KZOyw9unS2.drCAbBI7IEVLCK.qX7H/28oKhVME0vq',
  email: 'admin@admin.com',
  firstName: 'Admin',
  lastName: 'User',
  id: 1,
  roles:
   [ { name: 'admin',
       created: Sun Jul 05 2015 03:06:07 GMT+0000 (UTC),
       modified: Sun Jul 05 2015 03:06:07 GMT+0000 (UTC),
       id: 1 } ] }

now you can clearly see the roles.

You can let your imagination go wild for all the ways you might use this power, for now we'll just move on.

loopback-console
Heath Morrison
reach out to him
package.json