hosting nodejs application in EC2


Question

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)?

1
28
8/19/2017 5:27:36 PM

Accepted Answer

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

41
1/2/2014 6:04:41 PM


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon