NodeJS give me the ability to write back-end code in JavaScript. It's the better framework to build real time applications.We can create applications using pure JavaScript.
Setup Environment
First thing to do get NodeJS installed on your system. For installation in Linux link .
After installing NodeJS we have to setup the following.
Creating Application
There is two ways to create applications in Node.
First create a file named package.json in your project directory and add the dependencies .
Setup Environment
First thing to do get NodeJS installed on your system. For installation in Linux link .
After installing NodeJS we have to setup the following.
- ExpressJS - this will manage the server and the response to the user.
- Template engine
- Socket.io - allows for real time communication between the front-end and back-end
Creating Application
There is two ways to create applications in Node.
First create a file named package.json in your project directory and add the dependencies .
{
"name": "login app",
"version": "0.0.0",
"description": "Authentication",
"dependencies": {
"socket.io": "latest",
"express": "latest",
"jade": "latest"
},
"author": "developer"
}
Navigate to project folder and execute
npm install
Within a few seconds, you’ll have all the necessary dependencies downloaded to the node_modules directory.
The other way is using ExpressJS we can create application follow the link.
Developing the back end create a file app.js with the following core expressjs code.
var express = require("express");
var app = express();
var port = 3000;
app.get("/", function(req, res){
res.send("It works!");
});
app.listen(port);
console.log("Listening on port " + port);
To initialize the application execute:
node app.js
Now the server is running go to browser and open http://localhost:3000/ and see:
'it works'
Also we can develop the front end using static and socket.io.
To see my application click here .
My code can be found here.