Wiki > Node.js
Node.js is a platform designed for easily creating fast, scalable network applications.
Node.js and npm are installed on our servers.
Usage
To run a file with Node.js, simply do the following:
node <name of file to run>
It is recommended to run it in a screen session so that you can close the SSH connection without Node.js terminating.
Simple HTTP Server Test
To verify that Node.js is working, the following is an easy and simple test that will run a HTTP server on a specified port.
A random port number between 10000 and 32767 is needed and will be used to access the HTTP server that we create. The port number 18667
has automatically been generated and will be used throughout this article, but can be changed if needed.
-
Create the file for this test
touch test.js
-
Copy the contents of the box below into the test.js file
test.js
var http = require("http");
var server = http.createServer(function(request, response) {
response.write("Hello World!");
response.end();
});
server.listen(18667);
console.log("Server is listening");
-
Start the HTTP server with the following command
node test.js
If you navigate your browser to http://server.whatbox.ca:18667/
, you should see "Hello World!".
Further Learning
API documentation can be found on their official website at https://nodejs.org/api
.
If you are just starting out with Node.js (or Javascript in general), http://nodeschool.io/#workshopper-list
provide great hands-on tutorials (NOTE: They require Node.js to be installed on the machine before you begin).