Live Editing and Debugging
Learn how changes are reflected in a running app and how you can debug it.
Live code editing
When the nodehello
container is running in development mode, you can edit index.js
, and Nodemon will restart the application when you save the file.
For example, examine line 17:
const message = `Hello ${ req.params.name || 'World' }!`;
and change Hello
to Hey there
:
const message = `Hey there, ${ req.params.name || 'World' }!`;
Practice
Click on the “Run” button and then click the URL on “Your app can found at:”; you will be able to see “Hey there, World!”
Now replace there
on line 17 with your_name, click on the “Run” button, and refresh the browser.
mkdir nodejs useradd -m node chown -R node nodejs clear cp -r /usercode/docker-compose.yml /usercode/nodejs/ cp -r /usercode/package.json /usercode/nodejs/ cp -r /usercode/.dockerignore /usercode/nodejs/ cp -r /usercode/Dockerfile /usercode/nodejs/ cp -r /usercode/index.js /usercode/nodejs/ cd nodejs clear docker-compose up
Remote container debugging
This section describes how to debug a Node.js application running in a Docker Container. The information in the section can also be applied to other runtimes with similar facilities.
Node.js debugging overview
To debug a Node.js application, you can:
-
Set the
NODE_ENV
environment variable todevelopment
. Many modules use this to show more verbose errors or record logs. It has been set in both Dockerfile anddocker-compose.yml
. -
Launch
node
with the--inspect=0.0.0.0:9229
parameter. This starts ...