Skip to main content

Noob introduction to Node.js

In this blog post I am gonna give you all a brief idea about Node.js.


Earlier JavaScript was purely used for client side scripting, and it was embedded to a html page.But the node js developers use it for server side scripting(to produce the content of dynamic web pages before sending it to the user.) Node.js is an open source, cross platform run-time environment that executes JavaScript code server side.

Why node.js?

Node.js uses asynchronous programming.

When a file request comes a ASP/PHP file would,
  1. Send the task to the computer's file system.
  2. Wait for the system to open and read the file.
  3. Sends the respond back to the client
  4. Get ready to handle the next task.
But as node.js is using asynchronous programming, it would handle the request in a different manner.It would,
  1. Send the task to the computer's file system.
  2. Handles the next coming task.
  3. Returns the respond of the first task to the client when the system has completed it.
In brief it reduces waiting and simply continues with the next requests.This is also known as the non-blocking I/O.

Now as you have an overall idea of what node.js is now let's get started with a simple piece of code.
Follow the below mentioned steps.

1.Before working with node.js you should have it on your machine.You can download it here

2.Now let's write a couple of lines of code to display "Hello" in the browser.

For that first create a node.js file with a suitable IDE (I will be using JetBrains WebStorm here).


2.Lets write the code to display "Hello" in the browser.After that we can run the server by typing "node <filename>.js" in the terminal.



3.Type http://localhost:8080/ in your brower and there you get "Hello" printed!




As now you have the ability to run a node application, it's up to you to go explore the more interesting stuff out there!!



Comments

Popular posts from this blog

NoSQL vs SQL

I am sure most of you all are familiar with SQL database and have worked with MYSQL, Oracle or other SQL databases. And obviousely you must have heard of "NOSQL" as well. So in this blog post we'll see what this NoSQL is and the key differences between NoSQL and SQL. What is "NOSQL"? NOSQL stands for Not Only SQL.It is an approach to database design that can accomodate a wide variety of data models.  NoSQL doesn't have a predefined schema and used for big data and real time web applications. There are several types of database types. 1.Key-Value : Stores data as key value pairs      Ex: Redis, Riak, Memcached 2.Document : Stores data as documents (JSON,BSON,XML)        Ex: MongoDB 3.Column : Stores data in column families as rows have many columns assosiated with.      Ex: Cassendra 4.Graph : Stores entities(nodes) and relationships(edges) between them and represent it in a graph.      Ex: Neo4j Benefits   of NoSQL Basicall

Getting started with React js

In this blog post, I'm gonna explain you all about React js, a javascript technology that is used to create interactive single page applications.

New features of Java 10

Hello all! In this blog post I am gonna tell you about the new features of java 10.I am pretty sure all of you have heard of Java 10! Well, some of you might have dive in to Java 10 as well. Noo? Then this blog post will be a good beginning for you to learn about java 10 and its new exciting features. I am not gonna tell you about all the features but I will be focusing on the features that I found more interesting. 1.Local Variable Type Inference  Java 10 onwards Java also will have the 'var' keyword like JavaScript. This allows you to specify a variable without mentioning the data type of that particular variable but Java compiler will identify the real data type of the variable you declared.And also note that this 'var' keyword can only be used when defining variables inside methods and variables inside blocks.Although Java 10 allows the users to define variables with 'var', that doesn't make Java a dynamically typed language because once the ty