Install Node.js with dependacies

sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
Advertisements

Apache and Node.js on the same Ubuntu server

Install Node.js

apt-get install nodejs
apt-get install npm
 apt-get install build-essential

Install express node module

npm install express

Edit Apache

sudo a2enmod proxy
sudo a2enmod proxy_http
edit the  default apache conf
ProxyRequests Off
<Proxy *>
 Order deny,allow
 Allow from all
 </Proxy>
 <Location /node>
 ProxyPassReverse  http://server-name:5000
 </Location>
Now restart the apache 
service apache2 restart
The first app
created two files: web.js and package.json
web.js:
varexpress = require("express");
varapp = express();
app.use(express.logger());
app.get('/', function(request, response) {
    response.send('Hello World!');
});
app.get('/test', function(request, response) {
    response.send('This was only a test');
});
app.use(function(err, req, res, next){
  console.error(err.stack);
  res.send(500, 'Something broke!');
});
varport = process.env.PORT || 8080;
app.listen(port, function() {
    console.log("Listening on "+ port);
});
package.json:
{
  "name": "node-example",
  "version": "0.0.1",
  "dependencies": {
    "express": "3.1.x"
  },
  "engines": {
    "node": "0.10.x",
    "npm": "1.2.x"
  }
}
Start the app
    node web.js