UNPKG

nodejslearnerfiles

Version:

Very Good Beginnings if you want to Learn Node.js

83 lines (61 loc) 1.85 kB
// Do a Git Clone and Obtain the NVM repository. git clone git://github.com/creationix/nvm.git /MEAN/nvm cd nvm chmod 755 nvm.sh ./nvm.sh // Install various versions of Node and set a default. -bash-4.2$ nvm install 0.8.15 Downloading and installing node v0.8.15... Downloading https://nodejs.org/dist/v0.8.15/node-v0.8.15-linux-x64.tar.gz... ######################################################################## 100.0% Computing checksum with sha256sum Checksums matched! Now using node v0.8.15 (npm v1.1.66) -bash-4.2$ -bash-4.2$ nvm install v6.9.1 Downloading and installing node v6.9.1... Downloading https://nodejs.org/dist/v6.9.1/node-v6.9.1-linux-x64.tar.xz... ######################################################################## 100.0% Computing checksum with sha256sum Checksums matched! Now using node v6.9.1 (npm v3.10.8) -bash-4.2$ -bash-4.2$ nvm ls v0.8.14 v0.8.15 -> v6.9.1 system default -> v6.9.1 node -> stable (-> v6.9.1) (default) stable -> 6.9 (-> v6.9.1) (default) iojs -> N/A (default) lts/* -> lts/carbon (-> N/A) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.14.1 (-> N/A) lts/carbon -> v8.11.1 (-> N/A) -bash-4.2$ // Finally you got the REPL -bash-4.2$ node > > > // Running a Sample Script using the Node.js -bash-4.2$ node timeout.js Hello World -bash-4.2$ cat timeout.js setTimeout(function() { console.log("World"); }, 1000); console.log("Hello"); -bash-4.2$ node -v v6.9.1 -bash-4.2$ // You can Spin Up a Simple HTTP server using the node.js and this is how you do it. var http = require('http'); http.createServer(function (req,res) { res.writeHead(200, {'Content-Type':'text/plain'}); res.end('Hello World\n'); }).listen(1337); console.log('Web Server running...'); // You will get a HTTP "Response" as "Hello World.." if you do, http://34.234.96.21:1337