Shyam Hande has Published 72 Articles

What is express.js and installing it in Node.js?

Shyam Hande

Shyam Hande

Updated on 13-May-2020 12:38:42

64 Views

Why requires express.js?Writing core node.js code to fetch request data and parsing it is complex enough. As we saw in previous posts, we wrote data and end event to get the simple request data.Express makes the process simpler. It helps developers to focus more on writing business logic instead of ... Read More

Understanding the use of debugger in Node.js

Shyam Hande

Shyam Hande

Updated on 13-May-2020 12:36:53

97 Views

In earlier example, we used debugger in vs code to check any logical error. In this article we will look into how to use debug console and restarting debugger automatically on changes.In debug console, we can also type an expression and evaluate its result beforehand. This is very useful in ... Read More

Understanding the different error types and handling in Node.js

Shyam Hande

Shyam Hande

Updated on 13-May-2020 12:33:34

279 Views

Error types are −Syntax errorRuntime errorLogical errorSyntax error −These are easy to find as most of the development tools like visual code studio shows red lines whenever there is a syntax error. The suggestion for resolution may be not be correct in tools but it gives an idea of what ... Read More

How to install third party packages using npm

Shyam Hande

Shyam Hande

Updated on 13-May-2020 12:30:31

524 Views

Now, so far we saw how to create a node project with npm init command and also adding scripts to run application.Why third party libraries are requiredWe used core modules of node.js like http, fs etc which are available by default with node.js but working only with these core modules ... Read More

Understanding the npm scripts in node.js

Shyam Hande

Shyam Hande

Updated on 13-May-2020 12:15:36

260 Views

So far we are running our App.js using following command −Node App.jsWe can use npm scripts to run or debug our app.How to start a node projectCommand is − npm initAbove command will initiate a project, it will ask few questions about project name and starting file name etc.As we ... Read More

Understanding the npm - Node module system

Shyam Hande

Shyam Hande

Updated on 13-May-2020 12:11:09

93 Views

In our earlier example of getting user input and storing it a file has only one file. But in real life scenarios, we will have to create multiple file to keep code simple and easy to read.Let’s see how to use module system in node.jsWe have App.js −const http = ... Read More

How Node.js works in background - A brief analysis

Shyam Hande

Shyam Hande

Updated on 13-May-2020 12:05:48

251 Views

Node.js uses only one JavaScript execution thread.Question is − how Node.js process multiple http or any other requests and there can be question on performance, security as well?Node.js starts event loop on application start and handles callback functions using it.Node.js maintains a worker pool. Long running operations are transferred to ... Read More

Understanding blocking and unblocking of code execution in Node

Shyam Hande

Shyam Hande

Updated on 13-May-2020 12:04:29

401 Views

Now, we have a file writing function writeFileSync in fs module as shown below −const requestBody = []; req.on('data', (chunks)=>{    requestBody.push(chunks); }); return req.on('end', ()=>{    const parsedData = Buffer.concat(requestBody).toString();    const username = parsedData.split('=')[1];    fs.writeFileSync('username.txt', username);    //redirect res.statusCode=302;    res.setHeader('Location', '/');    return res.end(); });Sync means ... Read More

Understanding the Event driven code execution approach in Node

Shyam Hande

Shyam Hande

Updated on 13-May-2020 12:02:44

104 Views

In earlier example in App.js , we saw how to parse data from request using data and end event.Code snippet below shows the if block for that −if(url === '/username' && req.method === 'POST'){    const requestBody = [];    req.on('data', (chunks)=>{       requestBody.push(chunks);    });    req.on('end', ... Read More

Parsing request Body in Node

Shyam Hande

Shyam Hande

Updated on 13-May-2020 11:57:25

2K+ Views

Earlier in simple code example, we saw how to route a request and creating a file to input the test data.Now, we want to save the user entered input data into text file.How Node.js handles incoming request dataNode.js reads data in chunks means it uses streams to read data . ... Read More

Advertisements