Creating a MongoLab account and database

In order to use MongoLab with our app in AWS, we first need to register a new account on https://mlab.com/ and create an AWS database subscription. After you register a new account and activate it using the link they send you via email, you can create your first database subscription.

From your main dashboard, click on the Create new button (with the lightning
bolt icon).

From the Create new subscription page, configure the following settings:

  • Cloud provider: amazon web services
  • Location: Whichever region you prefer
  • Plan: Select Single-node (development)
  • Select Sandbox (shared/free)
  • MongoDB version: 2.4.x
  • Database name: anything_you_want (I chose imgploadr)
  • Confirm that the price is $0 per month
  • Click on Create new MongoDB deployment

Going back to your main dashboard, you should now see that your new database has been created and is ready to go. The next thing we need to do is to create a user account that our app will use to connect to the server. Click on the database listed on the main dashboard and then select the Users tab. Provide a new username and password. After the new user account has been added, copy the URI located at the top of the screen (it only appears after a user has been added) that starts with mongodb://.

Now that you have the new URI connection string, we need to update server.js to include this new connection string in our mongoose.connect. Edit the file and update it with the following code:

mongoose.connect('mongodb://imgploadrdb:[email protected]
.com:61248/imgploadr'); mongoose.connection.on('open', ()=>{ console.log('Mongoose connected.'); });

Ensure that you replace <username> and <password> with the appropriate information from the user account you created on the MongoLab dashboard.

With our application code updated to point to the new MongoLab database connection string, we need to zip up the project files so that they can be uploaded via the AWS dashboard. From your computer's file browser, locate the project root that contains all of your applications' source code files, select all of them, and right-click on them to add to an archive or ZIP file. The name of the ZIP file can be whatever you choose. One thing to note is that you shouldn't include the node_modules folder with this ZIP file (the easiest solution might be to simply delete the folder altogether). The AWS online docs have a great write-up on creating ZIP files, if you need more information (https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.deployment.source.html).

Once your source code has been updated to use the new MongoLab connection string and you've created a ZIP file of the entire project (excluding the node_modules folder), you're ready to create the new AWS application and deploy your app.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.189.67