Jump to content
xTremeSurfer

install & hello world @nodejs in ubuntu!

Recommended Posts

Posted

Install nodejs:

1. sudo apt-get install python-software-properties

2. sudo apt-add-repository ppa:chris-lea/node.js

3. sudo apt-get update

4. sudo apt-get install nodejs

Hello world in nodejs:

1.Create a file named test.js.

2.Write this in test.js.


var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");

3.In terminal write: node test.js

Source: Hello Node! - How To Node - NodeJS

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...