In this second part of my node.js development investigation we will look at using Visual Studio as a development environment.
To begin open Visual Studio and select New Project.
From the available project categories select Web and then from the template select ASP.NET Empty Web Application. Select a location for the project and then give it an appropriate name.
You should now be faced with an empty web project in the Visual Studio IDE.
Delete all default files/folders that were created with the project. Now create a JavaScript file called app.js with the following contents:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
This is the sample code from nodejs.org homepage that creates a basic webserver that will respond to http requests on port 1337 with the plain text Hello World.
Next the Visual Studio project needs to be configured to start up node.js when run so we can test the webserver just created.
From the top menu select DEBUG and Start Without Debugging or launch with Ctrl + F5
A command window should now open with the address of the running server.
Copy this address into a browser and voila the page is served by node.js.
You now have a running server that is responding to requests and serving responses over http. At this point there is little you can actually do with this, the next posts will cover adding packages to serve CSS files and HTML pages in a structured way, connecting to a database to serve content and running node.js under IIS stay tuned!

















Login