mongodb, express.js app deployment best practices - node.js

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

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

How should we setup our database (MongoDB) and backend (Express) so that everyone can access the database remotely?

The Problem
I am student assigned to a project to create a rudimentary social media app. We are planning to use Flutter to build the app and we are going to use MongoDB and Express for the database and API respectively. The goal is to be able to use continuous integration for our project through Fastlane and GitLab.
Initially, I thought to put the API and Flutter in separate Docker containers and to host the database on my desktop, but I realize that might not be the best solution.
The Question(s)
How should we setup the database and the server that we all have access to the same data in a database? Basically, how should we best set up our project environment to work as team, in terms of:
hosting the database?
setting up Express and Flutter for continuous integration?
If you are using MongoDB just set up a cluster on Atlas it's free as long as it's a relatively small application (up to 500MB). After you sign up, you will create a cluster, and then Atlas will give you instructions on how to connect to that cluster using node.js.
Basically all you do is throw in the link to your cluster with your configured password in your database connection link. This is all in the cloud so you can access it from anywhere after you whitelist the IP's that will be accessing it remotely. (alternatively you can whitelist all IP's which is the easier way of doing things it's just A LOT less secure.) but it's an okay option for a school project.
You can then use Heroku to host your app which allows for a custom server setup like you will have with Express.
You will need to use dotenv for heroku as well as securing your database link and password, so read up on that as well.

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.

MongoDB on Azure Web APP

I'm running nodejs application via Azure Web App. How do I set up MongoDB on Web App service?
You need to provision MongoDB yourself and have your Web App work against it.
Azure doesn't have a native MongoDB service but you can:
Use Azure's DocumentDB with the Mongo driver compatibility
Use the MongoDB VM image from the marketplace (this is IaaS).
Use mLab which is a 3rd party hosted solution but can be bought from Azure

mongodb on cloud foundry / appfog

I am deploying nodejs app with mongodb db with collections/data in it. I have it under the data/db directory. it doesn't have username / password. but with the appfog the service has the user name/password. how does the mongodb service know to start with the db I deployed.
Thanks
When you create the MongoDB client you should pass server host/port and authentication information to it.
usually on hosted services such as Heroku or Appfog this info is provided in evncironment variables which can be accessed with process.env.VARIABLE_NAME

Resources