This set of instructions is specific to developing an app created with Strongloop's Loopback.
Suppose you have a Docker container or a Docker-compose script which launches multiple containers, and you would like to develop the code-base while your code is running inside the container (and the container(s) could run on localhost or remotely). This can be done with VS Code.
- Open VS Code (
code .
) inside the directory that contains the code-base opens the IDE). Install theRemote Explorer
extension. - Navigate to the directory containing the code-base, including the
Dockerfile
or thedocker-compose
file. Launch the container(s). - In VS Code, click on the Remote Explorer icon (on the left side of the window by default). You should see the container(s) listed. Pick the one that contains the code you want to develop, and connect to it.
- Hover over the container of interest, right mouse button, and click on
Connect to Container
. That action opens another instance of VS Code, which shows the content of the container. Navigate to the directory holding the code. Also, you should see a green bar on the lower left side of the screen that should say something likeContainer ...
describing the name of the container.
Now you're connected to the container. You can edit the code inside the running container, and it should affect the output.
Suppose you have a Node.js application running as a backend to some frontend. You would like to exercise some code in the backend that is called by some HTTP method in the front end.
-
Set a breakpoint at some line where you want the debugger to stop. Next hit
F5
or navigate to menuDebug
->Start Debugging
. In the debugger tab you should see that the debugger has attached to some process. -
Identify the endpoint that invokes the Node.js backend method and create a HTTP request that is tied to that method. In a terminal run
curl <METHOD> http://myendpoint.org
. -
The debugger should stop at the first breakpoint it passes, i.e., the red dot should be framed with a yellow arrow. Use
F10
and other keys to inspect variables and call stack. Et voila...