Node response.setHeader() Method
The `response.setHeader(name, value)` method, introduced in v0.4.0 of the ‘http‘ module, is used to set a single header value for implicit headers. If the header already exists in the headers to be sent, its value will be replaced. Multiple headers with the same name can be sent using an array of strings. Non-string values are stored as is, but when retrieved using `response.getHeader()`, they may appear as strings due to network transmission requirements. When headers are set with `response.setHeader()`, they are merged with any headers provided to `response.writeHead()`, with the latter taking precedence. Import the ‘http‘ module to use this functionality and obtain a proper response....
read more
Node response.writeHead() Method
The `response.writeHead()` property, introduced in Node.js v1.0, is part of the ‘http‘ module. It is used to send a response header to the incoming request. The status code represents a 3-digit HTTP status code (e.g., 404), and the headers parameter contains the response headers. Optionally, a human-readable statusMessage can be provided as the second argument....
read more
Node fs.rename() Method
The `fs.rename()` method is employed for the asynchronous renaming of a file, moving it from the specified old path to a designated new path. If a file already exists at the new path, it will be overwritten by the operation....
read more
How to Create and Verify JWTs with Node?
In this article, we will see how to create JWT tokens in Node.js. We will implement secure authentication in Node.js by creating and verifying JSON Web Tokens (JWTs) using libraries like `jsonwebtoken`....
read more
Node.js response.write() Method
The response.write() (Added in v0.1.29) method is an inbuilt Application program Interface of the ‘http’ module which sends a chunk of the response body that is omitted when the request is a HEAD request. If this method is called and response.writeHead() has not been called, it will switch to implicit header mode and flush the implicit headers....
read more
Node.js process.stdin Property
The process.stdin property is an inbuilt application programming interface of the process module which listens for the user input. The stdin property of the process object is a Readable Stream. It uses on() function to listen for the event....
read more
How to Run Many Parallel HTTP Requests using Node.js ?
We know NodeJS application is single-threaded. Say, if processing involves request A that takes 10 seconds, it does not mean that a request which comes after this request needs to wait 10 seconds to start processing because NodeJS event loops are only single-threaded. The entire NodeJS architecture is not single-threaded....
read more
Convert xml data into json using Node.js
XML: Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. The design goals of XML focus on simplicity, generality, and usability across the Internet. It is a textual data format with strong support via Unicode for different human languages. Although the design of XML focuses on documents, the language is widely used for the representation of arbitrary data structures such as those used in web services....
read more
How to get data from 2 different collections of mongoDB using Node.js ?
Mongoose is an Object Data Modeling (ODM) library for MongoDB. It defines a strongly-typed-schema, with default values and schema validations which are later mapped to a MongoDB document....
read more
How to do Pagination in Node.js using Sorting Ids ?
Implementing pagination in a Node.js application involves fetching and displaying data in chunks or pages, typically from a database. One common approach to pagination is using sorting IDs, where each record in the dataset is assigned a unique identifier (ID) that determines its position in the sorted sequence. This method allows you to efficiently retrieve data based on these IDs to implement pagination. Let’s dive into how you can achieve pagination using sorting IDs in a Node.js application....
read more
How to send data from client side to Node.js server using Ajax without page reloading ?
In this article, we are learning about how can we send data to a node server using Ajax without reloading the page from the client-side....
read more
How to Create Load Balancing Servers using Node.js ?
In node, Load balancing is a technique used to distribute incoming network traffic across multiple servers to ensure no single server becomes overwhelmed, thus improving responsiveness and availability. In this article, we’ll explore how to create a load-balancing server using Node.js....
read more