Static hosting with Node.js and Express

I'm trying to learn nodejs and I will use this knowledge to power the backend of a RIA such as ExtJS or Angular.

Anyway, to create a static folder to host web files in node, all you need to do is this:

npm install express
mkdir public
#place web documents in public folder

Write a node app:
app.js
var express = require('express');
var app=express();

app.use(express.static('public'));

app.listen(8080, function(){
  console.log("Static hosting activated");

});

Run the node app:
node app.js

Where is this useful? The public folder could be used to host your frontend application and library.

Comments

Popular Posts