Day 1 : Learn Node.JS in 30-days

Pradeep A
4 min readJan 22, 2024

--

Ah, Day 1! 🚀 The start of our Node.js journey! Have you ever questioned your motivation for delving into the Node.js world? Have its widespread appeal and the lively neighbour hood around it piqued your interest? 🤔 Now consider what it is about Node.js that appeals to you. 🌟

Now, let’s explore the BASICS OF NODE as we begin Day 1. Have you ever wondered why Node.js is appealing to developers? 🤓 It’s time to learn its secrets and investigate what makes it a unique force in the tech industry! Are you prepared to reveal the magic? Come on, let’s do this! 💻🎉

Why To Learn Node.JS

Of course! 🚀 It’s imperative to learn JavaScript in the modern, dynamic development environment. You should definitely learn it for the frontend, but here’s the real deal: if you use NodeJS for the backend, you’ll become a computer prodigy! 🎩💻

Why should I use NodeJS instead of PHP? NodeJS, on the other hand, is the superstar of backend technologies, dominating Silicon Valley and beyond! 🌐 For software developers hoping to advance in their professions, it’s the recommended option. 🚀

The best part is that NodeJS is not just incredibly powerful, but it’s also really easy to understand and write code for! 🎉 Imagine creating an app with only rudimentary functionality and then deciding it must become the global leader. Not to worry! With its Chrome V8 Engine, Node has you covered, enabling smooth scaling. 🌍⚙️

But How to Install Node in your Local System?

Installation Of Node.JS

  1. Visit the official site of Node.JS https://nodejs.org/en
  2. Download the LTS version of Node since it will be very stable rather than having new features with instability.
  3. As soon as the download finished Click on the MSI file to Install Node.JS
Click 'Next'
Check the box 'I accept terms and conditions'
Click 'Next'
Click 'Next'
In the custom setup check 'Add to path' Verify the checkboxes is checked.
Then 'Install'

4. After the Installation there will be downloads of additional packages. Do as directed by your System. These packages will be used in future.

Check Whether NODE.JS has installed properly on your system:
Open Command Prompt and type ‘node-v’
It will return the version of the node installed.

After the Installation of Node.JS install any IDE of your choice (VS Code recommended).

This indicates the successful Installation Node environment in your system.

Basics Of Node.JS

As previously established, Node.js is a cross-platform JavaScript runtime environment.
However, it used to develop console and web-based apps.
Console-based apps will run from the node command prompt.
Web-based programs run in Web browsers.

Let’s write our first application or first code, as we know the usual method in every languages we start from “Hello World!” Haha!

Step 1 : Create a file named index.js

Step 2: Write the Following code in the file.

console.log("Hello World");
console.log("Welcome to Node.JS Officially!!!");

Step 3: Run the index.js by running the following command in command prompt / terminal.

node index.js

// Output
Hello World
Welcome to Node.JS Officially!!!

Hurray. We finished our first application, which is simple but nevertheless a milestone. The above application is known as a console-based application.

Console Based And Web based application

Node.js supports loose typing, which means you don't have to specify what kind of data will be stored in a variable in advance. In Node.js, we use the var and let keywords to define any type of variable.

In JavaScript, there are various data types, including:

  • Number
  • Boolean
  • String
  • Null
  • Undefined

The null and undefined will cause a lot of uproar in constructing applications 😂; we’ll explore it later.

Objects are a data type that allows for the storage of multiple values using “name: value” pairs. Objects can hold any form of data.
For example, we will create data for a student:

let student = { 
name: "Baingan Guy", //String
address: "Insta Memes", //String
student: true, //Boolean
number: undefined, //undefined
regnumber: 007, //Number
};
// All datatypes together called object
// to access the object data
console.log(student.name);
console.log(student.regnumber);
console.log(typeof student);

//Output
"Baingan Guy"
007
object

Writing Functions in JavaScript/Node.JS

Functions in Node.js are defined by first using the function keyword, followed by the function name and any parameters that are provided to the function. We may check the number of arguments received and specify datatypes for the parameters in Node.js. Every guideline that is present while writing JavaScript functions is followed by Node.js functions.

Examples:

Example 1:
function printPerson(name,age) {
console.log('The person name is ' + name + 'and their age is ' + age);
}

printPerson("Ram" , 500);

//Output
The person name is Ram and their age is 500

Example 2:
function add(num1, num2) {
return num1+2; //returns sum of the two parameters.
}
let a = add(2,3);
console.log(a);

//Output
5

In the first example we passed two different types of parameters, i.e a String and a number. In the other one we passed both the parameters as Numbers.

There are other methods of declaring functions, we’ll discuss about it when frameworks starts.

The recap to execute the code / application once more
Launch “node index.js” or “node yourfilename.js” from the command prompt.

Outline of Today’s concepts:

  1. Why Node.JS
  2. Installation of Node.JS
  3. Basics of Node.JS
  4. Datatypes
  5. Objects
  6. Writing the first console-based application

Tomorrow we’ll get to know about Web-Based application.
Web-based application in simple words building web-servers.

Yes Web-servers excited righttt ??

Stay Tuned tomorrow at 7.30pm;

--

--

No responses yet