Navigate back to the homepage

how to check empty string in node js?

Infinitbility
Node
July 7th, 2022 · 1 min read
how to check empty string in node js?

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To check an empty string in node js, use the if..else statement just pass and put your string variable in an if condition if it’s empty it will go to the else statement.

In the following example, we will take the sample empty string and use the if..else statement.

1let str = "";
2
3if(str){
4 console.log("str is not empty");
5} else {
6 console.log("str is empty");
7}
8
9// str is empty

Today, I’m going to show you How do i check an empty string in node js, as mentioned above, I’m going to use the use if..else statement to check node js empty string.

Let’s start today’s tutorial how do you check an empty string in node js?

In this example, we will do

  1. take an example of an empty string variable
  2. use the if..else statement
  3. send the output in the response
1var http = require("http");
2
3//create a server object:
4http
5 .createServer(function (req, res) {
6 let str = "";
7
8 let output = "";
9 if(str){
10 output = "str is not empty";
11 } else {
12 output = "str is empty";
13 }
14
15 res.write(output);
16 res.end(); //end the response
17 })
18 .listen(8080); //the server object listens on port 8080

In the above node js example, we have taken the sample empty string variable, use the if..else statement, and send the output in the response.

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to get length of string in node js?

how to get length of string in node js?

An example of get length of string in node js with a step-by-step example.

July 7th, 2022 · 1 min read
node js convert string to number

node js convert string to number

An example of convert string to int in node js with a step-by-step example.

July 7th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]