Public Repository

Last pushed: 9 months ago
Short Description
Node.js with a loopback installed ready to build an API.
Full Description

Description

This image provides a Node.js with Loopback installed ( $ npm install strongloop -g).

Launch a container from the image

Once pulled, scaffold out an Rest API in minutes.
Launch the image as a container with:

$ docker run -i -t -p 3000:3000 -name loopback musketskier/loopback:v2 /bin/bash

First API, discovering loopback ...
Scaffolding it out ...

$ slc loopback

.. follow the prompts.
Once done move into the directory just created (cd <<api name>>) and create your first model:

$ slc loopback:model

... use a name that is meaningful as a resource in an endpoint (eg client)
... use db(memory) unless you have a database to persist content. To discover, it is simpler to do local memory first.
... use persistedModel
... custom plural: just hit enter
now for properties ...
... create a name as a string and no default value
... add other properties as needed
... hit enter at next property prompt when you are done.

start the app

Start the app ...

$ node .

Go to your browser as instructed. Use the root to see how long the app has been up.
Use the explorer to navigate out.

Alternative databases

Loopback can work with IBM DB2, MySQL, Oracle, MongoDB, .... as well as the initial default in-memory.
The above can be used in conjunction with a database in another container or server.
If you were to use MongoDB, you could

docker pull mongo:latest

Start the mongo container BUT give it a name so you can then link your node app here as well. Something like:

$ docker run -i -t -p 27017:27017 -name db mongo

Then you can start your node after by launching with

$ docker run -i -t -p 3000:3000 -name loopback -link db musketskier/loopback:v2 /bin/bash

Scaffold your app, then BEFORE you do any models, create a datasource

$ slc loopback:datasource

... using datasource name: MongoDB
... connector: scroll to MongoDB
... connection string to override: <blank> ... nothing for this setup
... host: localhost
... user: <blank> skip
... password: <blank> skip
... database: api (or any name that works for you)
... install loopback connector ...: yes

Now, go to model resources ensuring the database for each is [MongoDB (mongo)] rather than the default in-memory.
If that works, do not hesitate to leave comments.

Docker Pull Command
Owner
musketskier

Comments (0)