FAQ Database Discussion Community


Syntax error in loopback api gateway

node.js,gateway,loopbackjs,strongloop
I am following a tutorial :http://strongloop.com/strongblog/node-js-loopback-api-gateway-sample-applications/ and I am getting an error in the code underneath the Proxy heading in the link mentioned above. Code against the error is var proxy = require('./middleware/proxy'); var proxyOptions = require('./middleware/proxy/config.json'); app.use(proxy(proxyOptions)); { "rules": [ "^/api/(.*)$ http://localhost:3002/api/$1 [P]" ] } the error message is...

How log an HTTP JSON request in Loopback app deployed on Heroku?

node.js,logging,heroku,express,loopbackjs
An app (Loopback) is deployed on Heroku, and I need to to see the req body (the JSON) send to this app for debugging purpose. So the access to the log is : heroku logs --tail The server.js is like the following : var loopback = require('loopback'); var boot =...

Hide LoopBack PUT REST API method

node.js,loopbackjs,strongloop
How do I hide the PUT REST API method in LoopBack? I've been able to successfully hide many other methods, but not the PUT method. > $ slc -v strongloop v2.10.3 (node v0.10.35) ├── [email protected] ├── [email protected] (5a43a57) ├─┬ [email protected] (c945bd1) │ └── [email protected] ├── [email protected] ├── [email protected] (5e25e21) ├──...

Loopback: Cannot find module 'negotiator'

database,node.js,loopbackjs
I'm trying to use Loopback to create an api for my existing database. When I try to 'discover' the model, I get this error: Message: Cannot find module 'negotiator' Request: /workspace/api/DataSourceDefinitions/server.tweetvtds/testConnection Staus: 500 Error: Cannot find module 'negotiator' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Module.require (module.js:365:17) at require (module.js:384:17)...

Trouble setting up a Loopback production host on AWS EC2

amazon-web-services,amazon-ec2,permissions,loopbackjs,strongloop
I'm having trouble setting up a StrongLoop LoopBack production host on AWS EC2. I'm following these directions. This is what I tried. I created an EC2 server that's a Ubuntu Server 14.04 LTS. Then I: $ ssh -i ~/mykey.pem [email protected][ec2-ip-address] $ sudo apt-get update $ sudo apt-get install build-essential $...

Log in user with one-time token using Loopback

javascript,authentication,access-token,loopbackjs
I'm working on a Loopback application that has two types of users — a "Supervisor" that can self-register within the app and a "Subordinate" that can only be registered by Supervisors (and is tied to that person). Supervisors use an email and password to log in like the base User...

Add multiple dir for static files in Loopback

loopbackjs
Loopback has two areas where paths are set for static files: server.js var path = require('path'); app.use(loopback.static(path.resolve(__dirname, '../client'))); middleware.json "files": { "loopback#static": { "params": "$!../client" } }, In my dev environment I'd also like to reference another dir for example /node_modules How do I do this?...

How do I create a correct hasOne relation between two objects with loopback and angular

angularjs,mongodb,loopbackjs
I've recently started to code in angular as the frontend code and was planning to use loopback (www.loopback.io) as my backend (with a mongodb for my storage). Now, as a basic idea I'm just creating a login form and register form and will go on from there. Yet, I can't...

How Can I Return a Random Object in Loopback?

node.js,loopbackjs
I'm using loopback to build an application, and would like to write a custom remote method which returns a random model instance from the database. Is there a way to do this using the built-in ORM? Thanks!...

How do I access loopback data in the server?

javascript,node.js,socket.io,loopbackjs
I am currently using loopback (http://loopback.io/) to run an application, while most of the data is accessed on the front end using the angular SDK I also have a socket connection where I'd like to access this data. In server/server.js I've got var loopback = require('loopback'); var app = module.exports...

StrongLoop: EmbedsMany vs hasMany and belongTo

javascript,mysql,loopbackjs,strongloop
My App has this Events Models. If I create another Model: Dates... so an Event can have multiple Dates, should I use Events EmbedsMany Dates? or is better to use Events hasMany Dates and Dates belongsTo Event? What's the difference? New Dates to the event might be added later after...

Implementing Q with Strongloop Loopback

javascript,node.js,promise,q,loopbackjs
Q is a "supporting module" of loopback. I'm not totally sure what that means, but I'm assuming that it at least means that is possible to use Q with loopback's Persistent Model functions, like find() or findOne(). I'd like to know how to properly setup something like the following: app.models.Question.findOne({...

passing callback or promise to the different module , which one is better and efficient?

callback,promise,loopbackjs
In my application, I am passing callback to different module and so on. Same thing I am able to achieve using bluebird promise. According to best code practice, which one is better?...

StrongLoop Framework - Access-Control-Allow-Origin: *

angularjs,node.js,rest,loopbackjs,strongloop
I have an AngularJS / Strongloop project. The AngularJS part of the code is not hosted at the same location as the Strongloop project and as a result I'm running into a CORS issue. I have done a lot of reading on this issue, however I can't figure out how...

Amazon S3 browser direct upload unique file name

angularjs,node.js,amazon-s3,loopbackjs
I'm using Node.js and the Amazon aws sdk for signing an upload request so I can do direct uploads from an Angular application. It works really well except I can't get unique file names. I have tried with creating unique buckets instead but then I can't get the CORS settings...

Remote method for updating all records

loopbackjs,strongloop
I try to make a custom endpoint, which adds a bonus to all employee. And retorns all the employee records, just like the get endpoint. Something like /employees/bonus As I understand; I should make a remote method for this: common/models/employee.js Employee.bonus = function(cb){ // logic comes here cb(null,"") } Employee.remoteMethod(...

Best Practice For Consistent REST Status On Success/Failure (Using LoopBack)

loopbackjs
We're using LoopBack (by StrongLoop) for our REST framework. What is the best practice for determining success or failure? A successful result simply returns the the data (in JSON). An unsuccessful result returns readyState, responseText, status and statusText. It would be really nice if the successful result also returned a...

ACL on certain records instead of API URLs

loopbackjs,strongloop,loopback
I'm stuck with a scenario where a logged in user can create blog posts in a CMS like system. So he creates these posts in a backend system. When that user is on the Blog page in the admin panel in then an API request like this is sent: /api/blogs?filter={'userid':...

How to create a NodeJS + LoopBack Application using WebStorm?

node.js,webstorm,loopbackjs
I am using WebStorm v 9.0.3. I would like to create a Strongloop/Loopback Application + NodeJS Application. Is there a way to create it directly through WebStorm IDE or should we manually do it using commandline. Currently I can see only NodeJS Express App provision during project creation in WebStorm....

Cannot connect to StrongLoop PM using StrongLoop Arc

node.js,loopbackjs,strongloop
I'm having trouble connecting to StongLoop PM using StrongLoop Arc. I'm following these directions. Here's what I tried: # in one terminal window, I started up StrongLoop PM $ nvm install v0.12.4 $ nvm alias default 0.12.4 $ npm install -g strongloop $ slc loopback > name: hello-strongloop > directory:...

Createmany in Strongloop Loopback

loopbackjs,strongloop
I have an Order model which hasMany OrderItem models. But once a client wants to create an Order, it has to create an Order object first then for each product he added to his basket, he needs to create responding OrderItems separately. As you may notice it causes many reduntant...

How can I use body-parser with LoopBack?

node.js,express,middleware,loopbackjs,body-parser
I see that LoopBack has the Express 3.x middleware built-in. Indeed, body-parser is in loopback/node_modules. But I cannot figure out how to use it as middleware. I have never worked with Express 3.x, so maybe it's just that. require does not work, obviously, unless I install body-parser as a dependency...

Loopback - Include a Relation's Computed Properties

javascript,node.js,loopbackjs
I have a loopback app and I'd like to be able to include computed properties from relations in an API call. For example, say I have an apartment model and an address model. The address has properties city and state. I'd like to make one call, to the apartment model,...

findOrCreate in PersistedModal

loopbackjs,strongloop
I am using loopback. I wish to create record if it doesn't exist. I used Modal.findOrCreate method to maintain uniqueness but its showing me error of findOrCreate is not a function but Docs show it is. What I tried was. Poet.findOrCreate({where: {name: query.name}}, {name:query.name},function(response){ console.log(response); }); I am editing question...

Migrating built-in models to Databases

loopbackjs,strongloop
How to move built-in models like User, Roles, User-Role-Mapping etc... to the database we've created instead of the default datasource:db? The built-in models are not listing in Arc. I've tried creating a new model which inherits these base model. But, data is not saved into the new model. Please advice...I've...

Verification code rather than url in loopback

node.js,loopbackjs
I am using Loopback as an api for a phone app. How could I change the out of the box verification of an email address when a user signs up. I need it to be a 4 digit code (instead of a url) so that it's more friendly to the...

StrongLoop: mutual Model Relations

javascript,loopbackjs,strongloop,loopback
I have this app with 3 Models: Users, Events and Venues. An user can create events that take places in a venue, This are the relations: User: hasMany Event Venue: hasMany Event Event: belongsTo User But I'm not sure if Event must also belongsTo Venue? (as the Venue is not...

Loopback passport mobile login

facebook,mobile,passport.js,loopbackjs
I'm developing an API with loopback and passport. I've seen this example, which is quite good: https://github.com/strongloop/loopback-example-passport In the documentation, they say loopback follows this step to authenticate users via third party providers: A visitor requests to log in using Facebook by clicking on a link or button backed by...

Android Native FB Login with Loopback.io and Passport.js?

node.js,facebook,loopbackjs
I am building a android client for my app which already has a web client and uses loopback-component-passport for FB authentication. I am able to successfully get the access_token from FB through my Android App. I figured out that the default passport component with loopback works by doing a GET...

How do I get the MongoDb connection from inside Loopback.io

mongodb,loopbackjs
I'm writing a remote method that would be greatly enhanced by running an aggregation pipeline query. To do that I need to get the actual mongodb connection and work with it directly. How can I run something along the lines of module.exports = function(ZipCodes) { ZipCodes.pipeline = function (cb) {...

Is it possible to get the current User’s roles accessible in a remote method in Loopback?

loopbackjs,strongloop
Is it possible to get the current User’s roles accessible in a remote method in Loopback? I’m trying to allow a remote method to either return a subset of data based on a find using a where filter & current userId but in the case of an admin user, I...

strongloop slc deploy env var complications

deployment,loopbackjs,strongloop
I've been deploying a loopback app via a custom init.d/app.conf script, using slc run --detach --cluster "cpu", but want to move to using strong-pm, as recommended. But I've come across some limitations and am looking for any guidance on how to replicate the setup with which I'm currently familiar. Currently...

Can I get to response headers in Loopback afterRemote hook?

express,loopbackjs,strongloop,keen-io
I have a Loopback model on which I am logging requests to keen.io using the afterRemote hook. http://docs.strongloop.com/display/public/LB/Remote+hooks#Remotehooks-ctx.result I am also using the response-time package to add the response time header to the response. https://github.com/expressjs/response-time This is working fine, expect I cannot figure out how to get to the X-Response-Time...

LoopBack: How to Dynamically Create Custom REST Endpoints In Code (On The Fly)

rest,dynamic,endpoint,loopbackjs,strongloop
We are using the LoopBack REST framework to expose our database (and business logic). We need to allow our customers to create custom tables in the database (single and multi-tenant) which can be accessed via a REST endpoint. All customers need to use the same common (production) REST endpoints which...

What's the difference between embedsMany and hasMany in Strongloop loopback

relationships,loopbackjs
At first sight they seem to do the same thing: define a one-to-many relation So why would you choose one or another?

Loopback return an existing record on PU/UPSERT

postgresql,loopbackjs,upsert
I have the following PostGreSQL Locations table: -------------------- | ID | Name | -------------------- | 1 | Kitchen | -------------------- | 2 | Bedroom1 | -------------------- ID is a sequential PQ and Name has a unique constraint. Locations.json Name property has "index": { "unique": true }, And Locations.js includes Location.validatesUniquenessOf('Name');...

How to add more remoteMethod to Built-in Models (say User) in Loopback

node.js,express,loopbackjs,strongloop
How to add more remoteMethod to Built-in Models (say User) in Loopback? I have created a common/models/user.js and added the following code var loopback = require('loopback'); var User = loopback.User; User.signup = function(userData, callback){ // Validate data // Save data - User // Create role mapping // return token }...

Getting joined data from strongloop/loopback

node.js,loopbackjs,loopback
How can I get data from two joined tables? Suppose, there are two models called Category (CategoryId, CategoryName) and Product(ProductId, ProductName, CategoryId), Is there a way to get a result like:(ProductId, ProductName, CategoryId, CategoryName)

Loopback - GET model using custom String ID from MongoDB

database,mongodb,model,loopbackjs
I'm developing an API with loopback, everything worked fine until I decided to change the ids of my documents in the database. Now I don't want them to be auto generated. Now that I'm setting the Id myself. I get an "Unknown id" 404, whenever I hit this endpoint: GET...

Strongloop Loopback: Filter by id of related Model

javascript,angularjs,node.js,loopbackjs,strongloop
I have a Strongloop Loopback Node.js project with some models and relations. The problem at hand My problem relates how to query only those Media instances that have a relation to a certain Tag id, using the Angular SDK - while not querying Tags.media (which return Tag instances), but instead...

LoopBack installation failed with error code “ECONNRESET”

node.js,loopbackjs
I wanted follow this tutorial and one of the first steps - the installation of LoopBack failed. The type npm-debug.log tells: 41099 error argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "strongloop" 41100 error node v0.12.2 41101 error npm v2.7.4 41102 error code ECONNRESET 41103 error errno ECONNRESET 41104 error syscall...

LoopBack Remote Methods and Access to Model Data

node.js,loopbackjs
I've been working on this for hours and I'm completely lost, because the loopback documentation is not helpful. I'm trying to write application logic into a model. The documentation for that is here. Unfortunately, the example doesn't demonstrate anything useful other than passing an external value into the remote method...