Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

To get length of string in node js, use the String length property it will return your string char count.

The length property of a String object contains the length of the string, in UTF-16 code units. length is a read-only data property of string instances.

In the following example, we will take the sample string and use string length to get a count of the string.

let str = "infinitbility";

console.log(str.length) // 13

Today, I’m going to show you How do i find the length of a string in node js, as mentioned above here, I’m going to use the use String length property.

Let’s start today’s tutorial how do you get the length of the string in node js?

In this example, we will do

  1. take an example of a string variable
  2. use the string length property
  3. print the length of string on the page screen
var http = require("http");

//create a server object:
http
  .createServer(function (req, res) {
    let str = "infinitbility";

    res.write("infinitbility string length is " + str.length); //write a response to the client
    res.end(); //end the response
  })
  .listen(8080); //the server object listens on port 8080

In the above node js example, we have taken the sample string variable, find the string length, and return the response.

I hope it helps you, All the best đź‘Ť.