0

I've created an Amazon EC2 Ubuntu instance to test some nodeJS files and JS files.

I've managed to install NodeJS and MongoDB there, and I do have a publicIP.

Now, where should I upload the files in order to access the file from the browser? Something like myPublicIP/index.html

I've read here that I should use the /var/www/html directory, but I haven't found it when trying to locate using cd var/www/html.

Should I create that directory?

Soren
  • 14,402
  • 4
  • 41
  • 67
Rosamunda
  • 14,620
  • 10
  • 40
  • 70
  • What framework are you using for your nodejs app? I'm guessing (not clear) that by "accessing from browser", you really mean starting your nodejs app start serving http via nodejs. Simple answer is probably that you should do it pretty much as you do it on your dev box. – Soren May 08 '16 at 03:39
  • Thanks for your comment! I've just installed nodeJS and I was planning to test it, but for now, I just wanted to add an html document with some JS in it, and access it from the browser. – Rosamunda May 08 '16 at 03:47

2 Answers2

2

Nodejs is not a webserver -- unlike what you have with Apache or Nginx -- but there are several frameworks that implements the basis for webserver functionality, plus much more.

A simple and frequently used framework is express (which you install into your nodejs app by $npm install express --save)

The express guide has a number of different examples on handling requests, including how to use middleware for parsing urls, and you can simply write a simple webserver in a few lines.

You should also check out some of the extensive examples in the answers in this question as well: Using node.js as a simple web server

Community
  • 1
  • 1
Soren
  • 14,402
  • 4
  • 41
  • 67
1

You only need /var/www/html when you are using Apache, which is not your case since you are using nodeJS.

You just need to upload your code to a folder in EC2 and then start it using

node file.js

If you do it that way however, the moment you close your terminal, all connections are lost and your node server stops listening for new incomming connections. Your EC2 instance also need to have rules in security groups to allow incoming traffic to the door you are listening.

Vini.g.fer
  • 11,639
  • 16
  • 61
  • 90