The billion dollar app (Node.js! MongoDB! Clouds!)

Published: 2013-07-29
Today, I'd like to show you how to build a basic web app running on EC2 and connecting to a MongoDB instance running on MongoLab. We used Python so far, so why not use Node.js this time around: Javascript and JSON should work with MongoDB, huh?

We'll start from the same Ubuntu VM running in EC2. Only a little bit of extra setup is required.

First, make sure you open a port for your web app (say, 8080): in the AWS console, go to the "Security group" section and add a custom rule opening port 8080/TCP. Don't forget to click on "Apply rules changes" ;) No need to restart your VM, the change is effective immediately.

Then, 'ssh' into to your VM and install the packages required by Node.js: the environment itself plus its package manager:

ubuntu@ip-10-48-45-182:~$ sudo apt-get install nodejs npm

Now, let's install the native MongoDB driver used by Node.js:

ubuntu@ip-10-48-45-182:~$ npm install mongodb

This generated errors on Ubuntu 12.04, but the package still got installed. YMMV.

All right, now to the good stuff. Here's our web server in Node.js:
Everything will run asynchronously, which is pretty much the point of Node.js, but this is out of scope for today. I strongly recommend the Node Beginner website if you'd like to know more.



Pretty cool, yeah? Let's start this program on our VM:

ubuntu@ip-10-48-45-182:~$ node www.js
Web server started
Connected to database

Our web server is now running. Yes, really. Now, let's connect to our instance from another machine. I'll use 'curl' but your web browser will work too (feel free to actually try, my VM may be running):

$ curl http://ec2-54-216-192-183.eu-west-1.compute.amazonaws.com:8080/

And this, ladies and gentlemen, is a super scalable, state of the hype, cloud-based web application. Anybody wants to buy it for a billion dollars? :D

Until next time, read, learn and write some code!

About the Author

Julien Simon is the Chief Evangelist at Arcee AI , specializing in Small Language Models and enterprise AI solutions. Recognized as the #1 AI Evangelist globally by AI Magazine in 2021, he brings over 30 years of technology leadership experience to his role.

With 650+ speaking engagements worldwide and 350+ technical blog posts, Julien is a leading voice in practical AI implementation, cost-effective AI solutions, and the democratization of artificial intelligence. His expertise spans open-source AI, Small Language Models, enterprise AI strategy, and edge computing optimization.

Previously serving as Principal Evangelist at Amazon Web Services and Chief Evangelist at Hugging Face, Julien has helped thousands of organizations implement AI solutions that deliver real business value. He is the author of "Learn Amazon SageMaker," the first book ever published on AWS's flagship machine learning service.

Julien's mission is to make AI accessible, understandable, and controllable for enterprises through transparent, open-weights models that organizations can deploy, customize, and trust.