Node.js
bogotobogo.com site search:
What is Node.js?
Node.js is a way of running JavaScript on the server, but it's more than that.
- A platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications.
- Uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.
- Perfect for data-intensive real-time applications that run across distributed devices.
install
The steps of installing Node.js under hosting environment are:
- Log in to your account using SSH.
At the command prompt, type the following commands:
cd ~ export TMPDIR=~/tmp
-
To download the latest version of Node.js, type the following command:
wget http://nodejs.org/dist/node-latest.tar.gz
-
To extract the Node.js files, type the following command:
tar xvzf node-latest.tar.gz
-
To rename the Node.js folder to the
more convenient nodejs name, type the following command. Replace X.X.X with the version number on your account:
mv node-vX.X.X nodejs
-
To build and install Node.js, type the following commands:
cd nodejs ./configure --prefix=~ make make install
- After these commands finish, Node.js is installed on your account.
-
We may need to set a path for node in ~/.bashrc:
export PATH=$HOME/bin:$PATH
installed files
The installed files are:
interactive node
Once Node.JS installed, we have an access to a new command called node. We can use the node command to execute raw JavaScript code:
$ node > console.log('Hello World'); Hello World undefined >
Another test:
$ node > function testNode() {return "Node is working"}; testNode(); 'Node is working' >
running a file
The most common way of running node is executing a JavaScript file (for example, hello.js):
console.log('Hello World');
$ node hello.js Hello World
AngularJS
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization