user2925994
user2925994

Reputation: 37

nodejs default doc on ubuntu

I'm entering new territory here. Not a linux guy at all, but I acquired a dedicated server from my hosting company, Ubuntu 12.0.4 running apache2. I have my domain name that successfully resolves to that server (basic html 'Hello World' index page shows up fine).

I've installed npm, node and express and they are (far as I can tell) working properly. I've added this app to the root as 'hello.js':

  var express = require('express');
  var app = express();

  app.get('/', function(req, res){
    res.write("Hello World");
    res.end();
  });

  app.listen(process.env.PORT, function(){
    console.log("Server Started");
  });

After i putty in (term?) and run 'node hello.js' I get the 'Server Started' message. But no results when I go to my domain. If I have an index.html page, I get it's contents. If I remove it, I get a dir listing.

How do make hello.js the sites default doc? Or, more generally, how do I set entry points to run node sites on a lve server with this config? I can write node, but deploying is turning out to be quite a bit harder than expected. Can anyone help?

Upvotes: 1

Views: 102

Answers (1)

Daniel
Daniel

Reputation: 38761

What you're seeing is the result of hitting Apache. Not your Node.js server.

Try starting your server like this from the command line:

$ PORT=8080 node hello.js

Then point your browser to:

http://www.youdomain.com:8080/

That will start your node.js process on port 8080. The first argument to app.listen is process.env.PORT which is an environment variable that you're setting on the command line with the command above.

This should work so long as you don't have port 8080 blocked in a firewall between your server and your local machine.

If you want Node.js to power your whole web site on the standard port 80 then you'll need to disable Apache first or set it up as a reverse proxy.

Upvotes: 1

Related Questions