[FSF Associate Member] View Annang Sowah's profile on LinkedIn

Tuesday 13 September 2016

Part 1 : Node JS - The Server-Side Javascript Framework In Vogue @ 2016 A.D

Well, there are about a dozen of Javascript(JS, not Joseph Sowah) frameworks on offering currently online.

Before making a choice of whichever, one will need to be clear about the specific purpose of any such JS framework. Some have specialty at performing client side or browser-based events whiles some perform server-side "heavy weight" changes e.g. database access, file retrieval, binary object storage etc.

I present to you the very-solid Node JS framework. This event-driven framework gives you all the power to perform some heavy-duty server side activities as earlier stated.

Enough of the talk, lets delve into the Node side of life!

Just a little note!
a. my screen shots will be taken from my Linux(Debian-based linux) computer and therefore some of the commands and stuff may not work if you are using a Windows box e.g. node installation, script creation etc
b. The command nodejs may just be the equivalent of node per your NodeJS software version and installation on your computer.

1. Install Node JS or confirm its installation - if already installed.










2. Also install or confirm the availability of the Node Package Manager, npm.










3. Create your first node script file to test Node JS.
As shown below, I have created a file labeled nodetest.js in a folder titled nodebase.

Create a script file either visually or using the linux shell i.e. touch
When done, display the list of available files to confirm the creation of the nodetest.js script.









4. Code a sample display message in the script-file i.e.







Alternatively, the file content can be constructed using below:

echo "console.log(\"Welcome, Joseph Annang Sowah\")" > nodetest.js 

Take note of the \ used to escape the special character "".
 


5. Run the nodetest.js script to test the readiness of Node.








6. Now that we have node executing our scripts successfully, we will proceed to setup the node server and verify its running in the browser.
Create a file, as done for nodetest.js, and label it nodeserver.js.









Put in this file our configuration for the new node server: basically the port number and any cool welcome message.

var http = require("http");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Joseph Annang Sowah welcomes you, Node Server Listening on port 8888");
  response.end();
}).listen(8888);


Save the file.

7. Start the node server by executing the nodeserver.js script.






NB. Make sure the node executables are on your system path or run the command below from the node executable folder.

8. Confirm the running of your Node server from the browser










9.We are hereby done with the first part of the NodeJS blog tutorial. Watch out for part 2 soonest.

Credit goes to one of the world's best NodeJS evangelists by name Manuel  Kiessling (http://leanpub.com/nodebeginner) for the "simplicity and depth of understanding" he brings to the Node JS technology.

No comments:

Post a Comment