![]() ![]() This is the power of the database service we used. In the above media, I uploaded a new photo and then refreshed the application over and over again to check if we lost any data but we didn't. Here's a link to the visual representation of the process: Now if you try to upload a random image and also refresh the page, we'd still have the image available to us along with the rest of the existing images. We made a change and redeployed our application and we can still see our images (data) available. If you did the above instructions correctly, you should see the header text color change from black to blue like so: It's very easy to create a database service with Cloud Foundry we can do that by running the following command:Īfter adding the above piece of code, we will push our application again so that we can see the changes.Īfter pushing, wait for it to deploy and navigate/refresh to the generated route link to see the changes happen. What a database service will do for us is to persist data we've uploaded into our application so that even if we push our application on Cloud Foundry over and over again, we'll still have access to the existing data we've uploaded into our application database. When you cf push, an entirely new version of your application is deployed and all old data will be deleted. Well, we need a database service because we cannot use a local database server when we deploy our application live and also to persist data. We need to create a MongoDB database service to fix this error and use the connection URI it provides for us. We are getting this error because Cloud Foundry cannot recognize or see any connection URI for our MongoDB database. If you've not noticed already, when we push the application initially, it throws an error that looks like this: You can deploy to the application by running the following command: ![]() Let's test this theory by deploying our application on Cloud Foundry. We need a database service to help us manage the database when it's deployed live. While this works locally, we cannot use the local MongoDB server when we deploy our application on Cloud Foundry. If you run the application by running yarn start on your local machine and with a local MongoDB server, you'll get the following in your browser when you navigate to localhost:8080or the PORT number you provided in the. MONGO_URI = MongoDB service connection URI (this will be provided when we create a Cloud Foundry database service).ĬLOUDINARY_CLOUD_NAME = This will be available on your Cloudinary dashboard after registration.ĬLOUDINARY_API_KEY = This will be available on your Cloudinary dashboard after registration.ĬLOUDINARY_API_SECRET = This will be available on your Cloudinary dashboard after registration. NODE_ENV = The current deployment environment, i.e development or production. Run the following command to clone the application to your machine:Įnter fullscreen mode Exit fullscreen mode To get started, we have to clone our application from Github and install its dependencies on our machine. MongoDB handles the storing of the image urls that are used to display the images on the client-side. The server-side of the application is written in Node.js.Ĭloudinary handles the storing of images that are uploaded. The client-side of the application is written with EJS. (I'll be using anynines for the sake of this tutorial).Ī Cloudinary account for storing images that'll be uploaded (API key and API Secret).īasic Knowledge MongoDB, Node.js and Cloud Foundry We will also make a few changes to our deployed application and re-deploy our application to see how fast Cloud Foundry updates our application in the browser.Īny Cloud Foundry distribution account. I'll demonstrate how to use a database service we will create in our application to read, write data to our application and also persist data. In this tutorial, we will be deploying a full stack application on Cloud Foundry with a Node.js backend and a MongoDB database service. I also gave an introduction to what services are in Cloud Foundry and how to get started with them. In the second part of this tutorial, I demonstrated how to deploy a Node.js application on Cloud Foundry, make a few changes to the deployed application to see how fast Cloud Foundry updates our application in the browser and finally, bind our application to a database service. ![]()
0 Comments
Leave a Reply. |