Solution tutorial: Modern Web Application using MEAN stack on IBM Cloud
This is a basic boilerplate for the MEAN stack (MongoDB, Express, AngularJS and Node.js) on IBM Cloud.
This application uses Databases for MongoDB and Code Engine on IBM Cloud.
The code and detailed steps are discussed in the IBM Cloud solution tutorial titled Modern web application using MEAN stack.
File | Description |
---|---|
.env.example | Set custom environment variables for your application. This is the proper way to store credentials and other sensitive values. |
server.js | Main server file that the Node.js runtime uses. It contains all the server logic. |
/server | Folder for files used by the Node.js server |
/server/models/user.model.js | Model for storing users in MongoDB |
/public | Folder for files delivered to users, such as html and css files |
/public/js/app.js | Angular application for manipulating and rendering data in browser |
There is also generous commenting throughout the application which helps explain critical parts of the application.
npm install
ibmcloud login
ibmcloud target -r ca-tor
ibmcloud resource service-instance-create mean-starter-mongodb databases-for-mongodb standard ca-tor
.env.example
file to .env
. Edir .env
to fill it the required values. You can run ibmcloud resource service-key-create mean-starter-mongodb-key --instance-name mean-starter-mongodb
to obtain the MONGODB_URL and CERTIFICATE_BASE64. Choose your own SESSION_SECRET.node server.js
to start your appNote that the code assumes a secured connection to MongoDB using SSL and a certificate. This way you can run the app locally but connect to IBM Cloud Databases for MongoDB.
An alternative way of running locally is using the provided Dockerfile
.
docker build . -t mean-stack:v1.0.0
docker run -p 8080:8080 --env-file .env -ti mean-stack:v1.0.0
The steps of creating the resouces (database, code engine project, secret, application, .env file, ...) described in Modern web application using MEAN stack are captured in the terraform file main.tf.
Getting started with solution tutorials has a description of how to get started with terraform on a workstation.
terraform init
terraform apply
Schematics is a cloud based Infrastructure as Code runner with cloud based state. It leverages the Terraform configuration described in the previous section.
Create a Schematics Workspace from this github repository
The link above should have opened a Schematics workspace in the create dialog with the github repository pre-configured and terraform 1.4 selected. Change the Workspace name, Resource group, and Location as desired. This will be the resource group of the workspace. The resource group of the resources created will be configured in schematics. Click Create.
In the Schematics workspace you can configure the variables before clicking Apply plan to provision the resources. Check out the Jobs tab - scroll to about the end of the Logs to see the endpoint URL that can be used to access the application.
In the IBM Cloud console create a private catalog and then add a product to the catalog:
Click on the Version in the Version list. It will walk through a wizard where the defaults are correct, just click Next in each page till you reach Validate version, and click Validate, to create a schematics workspace and resources.
After validation is complete create/configure or open the Security and Compliance and run a scan over the entire account using the IBM Cloud Security Best Practices version 1.2.0 profile by opening the profile and click Attach in the action menu. Frequency can be set to 30 days since the first scan will be run presently and that will provide the results that are required.
Create a project and then create a configuration in the project using the private catalog DA product version created in the previous step.
Please create a pull request with your desired changes.
The primary source of debugging information for your app running in the cloud are the logs. To see them, use the Code Engine web interface.
For more detailed information on troubleshooting your application, see the Troubleshooting apps section in the documentation.
See LICENSE.MD for license information.