Node.js is an event-driven I/O server-side JavaScript environment based on V8 the JavaScript engine used in Google Chrome. It is intended for writing scalable network programs such as web servers. It was created by Ryan Dahl in 2009, and its growth is sponsored by Joyent, which employs Dahl (extracted from Wikipedia definition...).

Installation from sources

Follow this tutorial to install the latest version of nodeJS from sources:

Installing nodejs v0.10.18

Node.js is a server-side software system designed for writing scalable Internet applications, notably web servers. Programs are written on the server side in JavaScript, using event-driven, asynchronous I/O to minimize overhead and maximize scalability.

Pratically this article is a copy of the original version available here tested on an CORE9G25 with Kernel 3.11 and EmDebian Grip Wheezy 7.1.

Node.js contains a built-in HTTP server library, making it possible to run a web server without the use of external software, such as Apache or Lighttpd, and allowing more control of how the web server works. Node.js enables web developers to create an entire web application in JavaScript, both server-side and client-side.

Installing steps

Install packages required to compile the source code:

~# apt-get install build-essential

Download the latest source code from nodejs.org:

~# wget http://nodejs.org/dist/v0.10.18/node-v0.10.18.tar.gz

Extract the tar archive

~# tar zxvf node-v0.10.18.tar.gz

Enter the directory we just extracted from the tar archive

~# cd node-v0.10.18

Change this files:

Compile and install

~/node-v0.10.18# ./configure
~/node-v0.10.18# make
~/node-v0.10.18# make install

The compilation time is very long, in the meanwhile a lot of message like:

  cc '-DL_ENDIAN' '-DPURIFY' '-D_REENTRANT' ...
  cc '-DL_ENDIAN' '-DPURIFY' '-D_REENTRANT' ...
  cc '-DL_ENDIAN' '-DPURIFY' '-D_REENTRANT' ...
  cc '-DL_ENDIAN' '-DPURIFY' '-D_REENTRANT' ...

are written on the console.

Test node.js to make sure it's working correctly

~/node-v0.10.18# echo "console.log('Hello World');" | node

This should simply print "Hello World" in the console. If you don't get any errors, node.js is installed and functional and you may just have executed your first node.js script.

Examples

Launch the nodejs interpreter typing:

~# node
> 

At prompt ">" type console.log("Hello"); to see if it works.

> console.log("Hello");                                                         
Hello                                                                           

Now we are ready to try the first nodejs example from its web site http://nodejs.org.

web1.js, add the follow contect to the web1.js file

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(81, "0.0.0.0");

console.log('Simple web running on CORE9G25');

This is an example of minimal web server written in Node that responds with a "Hello World" message to every web request.

Install the playground directory with all the code examples available on this site following this article: Programming examples on GitHub.

Then move into playground directory and type:

~# cd playground 
~/playground# cd javascript/                                             
~/playground/javascript# node web1.js
Server web running on board

Open a web browser and access to board URL on: http://fox_ip_address:81 to get the message "Hello World";

Related Links

Documentation Terms of Use
The Acme Systems srl provides this Debian system development and user manual.
The origin of these doc came from the website: http://www.acmesystems.it
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Creative Commons License

关注我们: 微博

销售邮箱:market@armdevs.com
技术支持: support@armdevs.com
销售电话: +86-755-29638421


核风在线支持>
在线时间:09:00-18:00
Copyright @ 2014 to 2020 - 核风智能技术有限公司