Category Archives: nodeJs tutorial

Get POST data In Express.js – Node.js


Get POST data In Express.js – Node.js: If you are using the Express.Js for Node.js you can get the post query strings ie. post parameters. Express.js is basically high class, high performance web development which is used for node.js. Here we are going to explain how to get the Post parameters passed from a Form using post method.


Get POST data In Express.js – Node.js

The html & Javascript Part are as below –

Html Part –

Suppose we have following form with the three input fields as below. We are going to post these values using this form.

Get POST data In Express.js – Node.js:

Javascript Part-

Here is javascript part in which we will get all the three fields posted using the form –

Get POST data In Express.js – Node.js:

app.use(express.bodyParser());
app.post('/', function(request, response){
    console.log(request.body.customer.name);
    console.log(request.body.customer.email);
	console.log(request.body.customer.phone);
});

Thus you can access any field posted from the Form.

Get Current Date time in Node.js


Get Current Date time in Node.js : You can retrive the current date time in Node.js using Date object. Here in this tutorial we are going to explain how to get current date time in Node.js


Get Current Date time in Node.js

Use the following syntax for getting the current date time –

Get Current Date time in Node.js:

var currdatetime = new Date();
console.log(currdatetime);

The above syntax will give the current date time.

For the newer browsers you can also use the following method quickly-

Node.js Syntax to Get Current Date time:

var currtime = Date.now();
console.log(currdatetime);

The above syntax will also give the current date time in milliseconds.

How to install nodejs on windows


How to install nodejs on windows : To install node.js on windows is very easy and simple. Follow the steps below and start working with node.js without wasting your time.


How to install nodejs on windows

Steps to install node js.

1. Download the appropriate(compatible with your windows) node.js from : http://nodejs.org/
2. Run the downloaded file.
3. After installing successfully let us run our first program.

Now create a file called as server.js place it in the folder where node.exe is placed.
server.js location:

how to install nodejs on windows

how to install nodejs on windows

Server.js file will contain :

var http = require('http');

http.createServer(function (request, response) {
    console.log('request starting...');

    response.writeHead(200, { 'Content-Type': 'text/html' });

    var html = '

Hello Tutorialsplane!

'; response.end(html, 'utf-8'); }).listen(8125); console.log('Server running at http://127.0.0.1:8125/');

Or Just Download the server.js file from here and place it in nodejs folder as in above image.

Download server.js

4. Now Open cmd.exe

Cmd

Cmd

5. Now run the following command :

“cd c:\path\to\the\node\executable” where node.exe exists.
For example my node.exe resides in the folder “C:\Program Files\nodejs>node”


C:\Program Files\nodejs>node server.js

After running this command you will see as following :

run node.js on windows

run node.js on windows

6. Now Open your browser and access http://127.0.0.1:8125/ in the address bar. You will see the following message :

Hello Tutorialsplane!