To learn a technology, we must first set up the development environment. It is easy to set up the nodejs development environment under Ubuntu, And it is OK to directly use apt-Get.
Sudo apt-Get install nodejs
If you do not like apt-get directly, you can download the source code package from the official website and compile and install it directly.
First install some necessary Libraries
Sudo apt-Get install build-essential OpenSSL libssl-dev PKG-config
Then download nodejs
Wget http://nodejs.org/dist/node-latest.tar.gz
Extract
Tar zxvf node-latest.tar.gz
Go to the nodejs folder for compilation and installation.
CD Node
./Configure
Make
Sudo make install
To delete the file, run sudo make Uninstall.
After the environment is set up, you can start to develop the nodejs program. Of course, the instance program needs to start from Hello world! Start.
var http = require('http');http.createServer(function(req,res){ res.writeHead(200,{'content-type':'text/html'}); res.write('Hello world!'); res.end();}).listen(3000);console.log('running on port 3000');
Run commands
Enter localhost: 3000 in the node hello. js browser, as shown in: