It is a more advanced example with a deployed NodeJS web application connected to a MongoDB backend. In this hands-on lab you will use the web console to inspect the running application.
-
Open the Firefox web browser and open the web console URL.
-
Select the htpasswd authentication method.
-
Use the user id and password to login
- Click the
Secrettab in the left panel
- Filter the names to find the
mongodbsecret and click on it.
- Scroll down and click on
Reveal values
You can see that Openshift created some random values if you didn't filled the form in the previous part of the tutorial.
You can find in this secret:
database-admin-passworddatabase-namedatabase-passworddatabase-user
For the following of the tutorial copy the database-admin-password.
- To better understand how the application can access the content of the secret. Go back to the
Topologyview and click theletschatdeployment
- Open the
Environmenttab and check that the secret is correctly linked to the application
- Click on the
Podstab and click the pod name
- Click on the
Terminaltab and run the command:env | grep database
You connected to the running container of the NodeJS application and you can see that the content of the secret is available as environment variables. The application can then read these variables to connect to the database.
For reference this is how to read an environment variable from a NodeJS application: process.env['database-user']
This application is using a MongoDB database, it's very convenient during the development to connect to the database and check the data created by the application. You will see how easy it is to do so with the Openshit Console.
- First, go back to the
Topologyview and open the MongoDB pod.
- Open the
Terminaltab and type the following command:mongo
- You are now connected to the MongoDB shell. Run the following commands to login into the database:
use admindb.auth("admin","<password from secret>")
If you missed to copy the database-admin-password from the secret repeat the step of the previous chapter.
- Use the command
show dbsto list the databases available. If you didn't changed the default values, you should see asampledblisted. Otherwise use the name of the database you created.
- Connect to this database and run few commands to check what is stored in the collections. Run the first command:
use sampledband thenshow collections.
You should see a list of five collections:
- messages
- rooms
- sessions
- usermessages
- users
- To query these collections you can use the following command:
db.<collection name>.find(), for example if you want to check the user you created in the previous part, run the following command:db.users.find().
You should see a JSON object with the user you created.
This conclude the second part of the hands-on lab.









