Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hosting nodejs application in EC2

I'm interested in hosting nodejs applications in a cloud and I'm looking for a free cloud hosting for my purpose. I've found that Amazon has one but I have the following question: Are there any tutorials around how I can set up and run nodejs application in Amazon EC2?

EDIT: Can you provide any good hostings for nodejs (except heroku)?

like image 423
Erik Avatar asked May 14 '12 06:05

Erik


People also ask

Can you run node js on AWS?

To set up an AWS Node. js environment in which you can run your application, use any of the following methods: Choose an Amazon Machine Image (AMI) with Node. js pre-installed and create an Amazon EC2 instance using that AMI.


2 Answers

I've been using Node.js with Amazon EC2 for a while and was quite happy with both of them. For the moment AWS seems to be the cheapest and the most robust cloud provider, so picking up Amazon wouldn't be a mistake. There's nothing special about running Node.js in the cloud - you work with it like if it were your own PC. Below are some general steps to follow for the simplest Node.js application running on EC2 Ubuntu server:

  1. Create Amazon EC2 account.

  2. From AWS console start t1.micro instance with any Ubuntu AMI (example).

  3. Login via SSH to your instance.

  4. Install node.js: sudo apt-get install nodejs

  5. Create new file test_server.js with the following content:

    require("http").createServer(function(request, response){   response.writeHeader(200, {"Content-Type": "text/plain"});     response.write("Hello World!");     response.end(); }).listen(8080); 
  6. Start the server: node test_server.js

  7. Check it's working from another console: curl http://localhost:8080

like image 164
nab Avatar answered Sep 24 '22 07:09

nab


Check out these tutorials (updated for 2021)

  1. How to Deploy a Node.js Application On AWS EC2 Server
  2. How to Deploy a Node.js application in AWS EC2
  3. How To Deploy Your Node.js App On AWS With NGINX And SSL
like image 32
almypal Avatar answered Sep 22 '22 07:09

almypal