Chinese Documentation : LoopBack FAQ

General questions

What platforms does StrongLoop support?

StrongLoop supports the following operating system platforms:

  • RHEL/CentOS 6.3 (RPM)
  • Debian/Ubuntu 12.10 (DEB)
  • Mac OS X Mountain Lion 10.8 (PKG)
  • Microsoft Windows 8, 2008 (MSI).  
    NOTE: Node does not support using Cygwin.  Instead use Windows Command Prompt for command-line tools.

StrongLoop supports the following cloud platforms:

Is LoopBack free? How much does it cost?

There are free and paid versions of LoopBack. See http://strongloop.com/node-js/subscription-plans/ for more information.

LoopBack uses a dual license model: you may use it under the terms of the open source MIT license, or under the commercial StrongLoop License. See the license file for the full text of both licenses.

Is there a developer forum or mailing list?

Yes! The LoopBack Google Group is a place for devlopers to ask questions and discuss LoopBack and how they are using it. Check it out!

For links to other developer community resources, see StrongLoop Community.

What client SDKs does LoopBack have?

LoopBack has three client SDKs for accessing the REST API services generated by the LoopBack framework:

  • iOS SDK (Objective C) for iPhone and iPad apps.  See iOS SDK for more information.
  • Android SDK (Java) for Android apps.  See Android SDK for more information.
  • AngularJS (JavaScript) for HTML5 front-ends. See AngularJS JavaScript SDK for more information.

Which data connectors does LoopBack have?

LoopBack provides numerous connectors to access enterprise and other backend data systems.

Database connectors:

Other connectors:

Additionally, there are community connectors created by developers in the LoopBack open source community.

Why do curl requests to my LoopBack app fail?

If the URL loads fine in a browser, but when you make a curl request to your app you get the error:

curl: (7) Failed to connect to localhost port 3000: Connection refused

The cause is likely to be because of incompatible IP versions between your app and curl.

Icon

On Mac OS 10.10 (Yosemite), curl uses IP v6 by default.

LoopBack, by default uses IP v4, and curl might be using IP v6. If you see IP v6 entries in your hosts file (::1 localhost, fe80::1%lo0 localhost), it is likely that curl is making requests using IP v6. To make request using IP v4, specify the --ipv4 option in your curl request as shown below.

$ curl http://localhost:3000 --ipv4

You can make your LoopBack app use IP v6 by specifying an IP v6 address as shown below:

app.start = function() {
  // start the web server
  return app.listen(3000, '::1',function() {
    app.emit('started');
    console.log('Web server listening at: %s', app.get('url'));
  });
};

Detailed questions

Once you start working with LoopBack, you may have more detailed questions.  Some of the most common are collected here, along with brief answers and links to the documentation for more information.

How do you perform a GET request to a remote server?

First, you have to configure a data source using the REST connector. In the datasources.json file that configures the data source, you can define operations against the REST API using the operations property.

For a short example, see loopback-faq-rest-connector.

Can an application respond with XML instead of JSON?

Yes: in in server/config.json set the remoting.rest.xml property to true.  See config.json for more information.

How do you send email from an application?

In brief:

  1. Configure a datasource to use the email connector.
  2. Map the built-in Email model to the the email datasource.
  3. Send an email using the configured model with Email.send().

See loopback-faq-email for a short example.

How do you use static middleware?

Static middleware enables an application to serve static content such as HTML, CSS, images, and client JavaScript files.  To add it:

  1. Remove the contents of the default "routes" property in middleware.json.
  2. Add the following to the "files" property in middleware.json: to serve static content from the project's /client directory.

    "loopback#static": {      
      "params": "$!../client"
    }

    Of course, change the value to use a different directory to contain static content.

See Defining middleware for more information, and loopback-faq-middleware for a short example.

What kind of hooks do models support?

Model hooks are functions that are executed when certain events occur in a model's lifecycle.  LoopBack models many different hooks, for example: afterInitialize after a model is initialized, beforeValidate / afterValidate (before and after  model validation), beforeSave / afterSave (before and after a model is saved), and so on.

See 模型钩子 for a complete list and more information.  See loopback-faq-model-hooks for a brief example.

User management questions

See Managing users for more information and loopback-faq-user-management for relevant code examples.

Note

How do you register a new user?

  1. Create a form to gather sign up information.
  2. Create a remote hook to send a verification email.

Notes:

  • Upon execution, user.verify sends an email using the provided options.
  • The verification email is configured to redirect the user to the /verified route in our example. For your app, you should configure the redirect to match your use case.
  • The options are self-explanitory except typetemplate and user.
    • type - value must be email.
    • template - the path to the template to use for the verification email.
    • user - when provided, the information in the object will be used to in the verification link email.

How do you send an email verification for a new user registration?

See step 2 in the previous question.

How do you log in a user?

  1. Create a form to accept login credentials.
  2. Create an route to handle the login request.

How do you log a user out?

  1. Create a logout link with the access token embedded into the URL.
  2. Call User.logout with the access token.

Notes:

  • We use the loopback token middleware to process access tokens. As long as you provide access_token in the query string of URL, the access token object will be provided in req.accessToken property in your route handler.

How do you perform a password reset for a registered user?

  1. Create a form to gather password reset information.
  2. Create an endpoint to handle the password reset request. Calling User.resetPassword ultimately emits a resetPasswordRequest event and creates a temporary access token.
  3. Register an event handler for the resetPasswordRequest that sends an email to the registered user. In our example, we provide a URL that redirects the user to a password reset page authenticated with a temporary access token.
  4. Create a password reset form for the user to enter and confirm their new password.
  5. Create an endpoint to process the password reset.

Note: For the resetPasswordRequest handler callback, you are provided with an info object which contains information related to the user that is requesting the password reset.