Hi Friends 👋,

Welcome To Infinitbility! ❤️

To convert a string to a number in node js, you can use the + plus operator it’s the fastest way to convert a string to a number.

In the following example, we will take the sample string variable, and convert it into an integer using the plus operator.

let text = "24325";

// using plus operator
let num = +text;
console.log(num) // 24325

Today, I’m going to show you How do i convert string to number in node js, as above mentioned here, I’m going to use the plus operator and string interpolation.

Let’s start today’s tutorial how do you convert string to number in node js?

In this example, we will do

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

//create a server object:
  .createServer(function (req, res) {
    let text = "24325";
    let num = +text;
    res.write(`${num} is ${typeof num}`); //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 example of converting a string to a number and return the convert number and their datatype in the response.

I hope it helps you, All the best 👍.