I'm new to Node.js and Loopback. I have been using Deployd so far and I'm trying to migrate to Loopback. The S3 bucket module on Deployd was working great.
So...:
I'm on this website https://github.com/strongloop/loopback-component-storage
I run, in my project folder,
npm install loopback-component-storage
I then need to create a datasource. To setup the new datasource, I tried
slc loopback:datasource
It doesn't provide me with the option to create a source that is a storage. So I rule that option out I guess
I see there is this piece of code on the github (link above):
var ds = loopback.createDataSource({
connector: require('loopback-component-storage'),
provider: 'filesystem',
root: path.join(__dirname, 'storage')
});
var container = ds.createModel('container');
app.model(container);
I guess this is the right way to create a datasource, but where do I place this code and how do I execute it? How do I adapt this code to work with Amazon?
{ provider: 'amazon', key: '...', keyId: '...' }
I suppose key is my secret key and keyId my access key id, but can you confirm?
I'm just having trouble getting started... thanks for your help in advance
Where to put the code: https://github.com/strongloop/loopback-component-storage/blob/master/example/app.js
app.js (1.x structure) or server/server.js (2.x structure)Amazon provider example: http://docs.strongloop.com/display/LB/Storage+service
You can add a datasource manually in server/datasources.json too. This way, you should be able to create a container model using the storage data source.
To do this by code as you illustrated, you can either modify server/server.js or drop a JS file into server/boot with an exported function as:
module.exports = function(app) {
// your code
};
Thanks @Raymond, I took the second option. I created file server/boot/xyz.js and put this in there:
module.exports = function(server) {
var path = require('path');
var ds = server.loopback.createDataSource({
connector: require('loopback-component-storage'),
provider: 'filesystem',
root: path.join(__dirname, '../../storage')
});
var container = ds.createModel('container');
server.model(container);
};
I cannot see the model in the explorer but I can call the service with:
http://localhost:3000/api/containers