DigitalOcean connect node.js to mongodb - node.js

I created and deployed a MERN web app on DigitalOcean which works fine using a Mongo database hosted on mlab.com, but now I want to host the database on DigitalOcean and I'm having difficulties with this...
I followed this tutorial https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-16-04 but now I don't know how to connect my node.js server to this database.
Does the connection to 127.0.0.1:27017/mydbname should work on production?
Any solution or advice would help me a lot.

Related

Cpanel Nodejs CRUD REST API giving response as "Incomplete response received from application" using Mysql DB

When i create a localhost nodejs CRUD API i am able to make post request.But when i deployed it in cpanel using nodejs software "Incomplete response received from application"
Please share more information as my preliminary guess is that if you are using MongoDB then you cant run it on shared hosting you should use some other DB like Atlas MongoDB or Mlab
I recommend you host it on Heroku as its also free
Deploy APP to Heroku
Use Any thirParty mongoDB service
Test your CRUD API

Need some guidance on deploying/hosting a web app

I recently developed a web app locally, with a React frontend that interacts via proxy with a Node.js backend that interacts with MongoDB Atlas. Everything works locally, and I am ready to actually deploy the web app for public use.
How does hosting work with a full stack web application? Do I host the entire web app in the same place (e.g. S3 bucket), or should the backend and frontend be deployed separately? I have never done this before, so I appreciate any help I can get.
Yes, you can have two different servers for frontend and backend.
You can use theHeroku platform to deploy your backend app, and Mlab to provision a Mongo database. These platforms has free tiers where you can experiment and learn about deployments and clouds.
Once you are comfortable with these then you can move to Elastic Bean Stalk on AWS to provision servers and also database.
Now mlab is not available as it is already been acquired by mongoDB only, so I would recommend you to create the database on Atlas cluster which also offers a free tier.
Rather than using the Heroku, I would suggest you to use MongoDB stitch which is also the backend as a service. If you will use stitch then you can also seek for support from mongoDB people but in case you will use heroku then you will not receive any support from them.
You can refer to the documentation of stitch for more information https://docs.mongodb.com/stitch/. This has complete guidance how you can deploy your app using stich and can use mongodb database.
However if you need more help, please ping me anytime.

Connect MongoDB to NodeJS on GAE

I'm running a NodeJS app on GAE and I want to connect to a mongodb cluster on Atlas.
I have white-listed my IP on atlas and established a connection. All work fine on my local machine.
When deployed my app on GAE it could not connect to Atlas since the IP is not white-listed. When I white-listed all IPs on Atlas I could make a connection and everything worked fine as on my local machine
I cannot assign a static-IP to a standard GAE app, therefore I must allow access from anywhere to my cluster on Atlas, which is probably a bad idea.
What would be best solution to work with mongoDB from a GAE standard app?
Any configuration I can make to Atlas? maybe switching to mLab? or any other ideas?
App Engine applications do not have fixed IP addresses. I'm not very familiar with MongoDB Atlas, but it does look like it offers an option to run on GCP and if that runs on a Compute Engine instance what you might be able to do is use the VPC Connector to enable access between your app and your MongoDB setup.

mongodb, express.js app deployment best practices

I have an API written in express.js, the db is mongo. I'm planning to use mlab
to deploy the DB. I don't really understand where to deploy the express api? Can i use AWS for api only? Is there any provider where i can host my DB and API at the same time? What are the best practices for deployment of these APIs?
"Best practices" is based on your needs. The current trend is to move everything to the cloud. So services such as AWS Elastic Beanstalk, Heroku, Azure App Service, and more will allow you to easily host your Express app with little to no setup/configuration on your end.
Each of the providers I've listed above have their own flavor of a NoSQL document storage.
Heroku - mLab add-on
AWS - DynamoDB
Azure - Cosmos DB
If you're set on NoSQL, then it's probably less of a headache for you to stick with mLab.
Here is my approach in AWS for simple apps
Number of servers :1
Application server and DB server are in same machine.
Setting up mongodb and nodejs in ec2 server with nginx as web server.
Nginx listen on port 80 and nodejs application running on port 3000
Using nginx reverse proxy to access the API endpoints

Deploying my app on Heroku using my own database

Currently I am deploying my app on a Heroku server. The app is written on Node.js and uses MongoDB as a database source. I'd like to know how I can upload my own database on Heroku without having to use any add-ons or databases provided by Heroku.

Resources