JavaScript has lived through several incarnations. Many of the early uses have been hard to forgive as well as forget. Starting with AJAX and Dojo and moving up through JQuery, perceptions of the JavaScript language have been changing. I even heard rumours that it was a full-fledged real computer language. When I heard of server side Node JS I knew it was time to take a look. If you can run JavaScript outside of a browser you can probably avoid the DOM and maybe JavaScript won't seem so bad.
Node JS and Express JS
Node.js is powered by Google's V8 VM. Want to execute "Hello World" to a terminal? Create a file named hello.js
console.log("Hello world!");
Execute it though Node.js
[allison@eckford hello-world-express]$ node hello.js
Hello World
Want to execute "Hello World" to a browser? You could use the http module that ships with Node.js. Or you could use express. Express.js and Node.js go hand in hand. Express is a web application framework for node. Create a file named app.js
var express = require('express');
var app = express();
// app.set('port', process.env.PORT || 3000);
app.get('/', function(req, res){
res.send('Hello World');
});
app.listen(3002);
console.log('Listening on port 3002');
Execute it through Express.js
[allison@eckford hello-world-express]$ node app.js
Listening on port 3002
Isn't that a lot easier than the first time you set up Apache?
I'm not suggesting it's time to retire your favourite Web Server but doesn't it look like quick and easy may have it's benefits?
Want to learn more about node.js?
- Read Felix Geisendoerfer’s excellent post Understanding node.js for additional background explanation.
- Read The Node Beginner Book by Manual Kiessling to get started with developing applications for node.js