Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Node.js on Windows (or JavaScript for the backend)

DZone's Guide to

Node.js on Windows (or JavaScript for the backend)

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

What is Node?

The simplest answer, albeit a simplistic answer, is that Node (or Node.js) is JavaScript on the server. Actually, it’s a more than just that, but you can read about the more in other places. This is a good enough answer for us n00bs.

Unless you’ve been living in in cave, you might have noticed that JavaScript is all the rage now. It’s the new assembly language of the Web. (It’s even for the enterprise.) With Node, you can now take that webby clienty goodness to your server applications.

The reason I’m brining all this up is because there’s now a version of Node.js for Windows. It’s currently the unstable release only, but it’s a sign of coolness to come. Furthermore, Microsoft has partnered with Joyent and Rackspace to make it happen. You can read about it here and here. The ultimate goal (according to the posts) is for Node.js to run on both Windows and Azure.

Now, I want to be clear too, since I have been newly assimilated, Node is not a Microsoft product..

Tutorial

I want to show you how easy it is to try out Node.

First, download the exe. I grabbed v0.5.2.

Next, run it. Yeah, it’s that easy. It used to be way harder.

You’ll be presented with a prompt and you can start writing JavaScript in paradigm-shifting REPL.

Now, let’s say you want to create a web server. We’ll begin by yanking the ‘hello world’ snippet from nodejs.org.

var http = require(‘http’);  
http.createServer(function (req, res) {  
  res.writeHead(200, {‘Content-Type’: ‘text/plain’});  
  res.end(‘Hello World\n’);  
}).listen(8124, "127.0.0.1");  
console.log(‘Server running at <a href="http://127.0.0.1:8124/’">http://127.0.0.1:8124/’</a>);  

I saved this snippet into a file named server.js. Then from a PowerShell prompt, I ran

.node.exe .\server.js

Next, I hit http://localhost:8124 with a browser and I got exactly what you’d expect.

Now you know enough to be dangerous.

Of course, you have to restart Node when you make changes to the file (use Ctrl + C). I’ll show you how I got around that in another post.

Have fun!

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Published at DZone with permission of Christopher Bennage, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}