Hi Folks ! Today’s we’re gonna learn how to set up or installing node.js using the homebrew. The step is simple and easy to learn. Even you’re new to node.js
But before we jump in into the Node.Js, you’re maybe wondering. What is Node.Js stand for ?
Node.Js or Node Javascript is JavaScript framework for using server-side runtime environment, which allows developers to create scalable and high-performance applications.
So, let’s jump in.
Step 1 : Turn on your windows or laptop
Well, what you gonna do if your windows or laptop not turned on ?
Turn on the laptop and wait until it finish booting your program
Step 2 : Open Terminal / Shell on your windows
Simply just click Command (for Mac) or Windows (for Windows) to open your Terminal. Then type “Terminal” or “Shell” (But, i prefer Terminal for easy use)
Step 3 : Open website and search homebrew
Now, open your default browser and search Homebrew. Copy the first command you found there
Step 4 : Install homebrew in your terminal
Copy it in your Terminal and just wait. (If your windows have a password, just put it down. Its very safe)
Step 5 : Install the platform you like
There is many platform out there but we use the most used platform, Visual Studio Code. Go there and download the platform.
Step 6 : Install node.js for homebrew
For the next step, write it down on your search engine browser “Node.Js for Homebrew”. And just like before, copy and put it down in your terminal. Wait until it finish and done. You’re ready to do some basic Node.Js code
Step 7 : Starting to Code
Before starting to code, make directory project file. So you know where it located. After that open your visual studio code. Your new VSCode will be like this.
Now in the side bar to the left. There are many options. Select the Extension (5th icons from the top) to download the ES6 JavaScript. For you who dont know ES6 JavaScript, ES6 or ECMAScript 2015 is the sixth version of ECMAScript and is a major update to JavaScript. ES6 introduces many new features that make JavaScript more powerful and easy to use.
Write down in the search on the extension “Javascript” and download the extension like this picture below.
After that, dont forget to install Live Share
(Its for easy to share to anyone who also used VSCode) and Thunder Client
(Its for running your JS Code in ease)
Now, move on to the main menu or the Explorer. Make sure you’re in the correct directory file you already made before. After that create a new folder in VSCode with the name src
After that, open new terminal in VSCode and write
npm init
There will be output like this.
In this section, just skip it (Press Enter) except the description and author. Write it whatever you like, but for easy build in the future, just put it the normal description. Wait for a few second and after that you will notice a new package.json
in your directory file.
For the simple JavaScript code syntax, we will learn let
and const
first. ES6 introduces two new ways to declare variables: let
and const
.
let
is used to declare variables whose values can be changed.const
is used to declare variables whose values can’t be changed
Now in the src
folder, add a new file named index.js
, open it and write down code like this :
let name = "Daniel"
let age = "20"
name = "John"
console.log("My name is " + name)
console.log("My age is " + age)
In your terminal, write down node src/index.js
and your output will be like this:
If you notice the output variable name
is “John” instead of “Daniel”. Meanwhile the variable age
is still the same. It’s because the name is defined with let
to declare the variable that values can be changed. So the values of variable name
is changed into “John”.
Now delete all code in the index.js
and put some new code :
const food = "Pizza"
food = "BBQ"
console.log("My Favorite food is " + food)
Same like before, in your terminal write down node src/index.js
and your output will be like this.
Whoaaa, why there is an error ? . Yeah, the error is because the variable food
is declared with const
so it values can’t be changed. And instead put an error in the terminal. So you’ll know if variable food
has value in it.
Step 8 : Evaluate your code
Now lets break down the code one by one:
let
is used to declared the variable that can be changed. This variable will be good for basic or simple project. But if it’s used in complex project, it will be a problem. Because the value inside the variable can be changed and can ruin the project.const
is used to declared the variable that can’t be changed. This function will be recommended function. It’s because the value can’t be changed and the project will run without an issue. So, you’ll know if a particular variable has been used.console.log
is used to print the output that we already write down. We also use double quotes (“ ”) or quote (‘ ’). Its for add new text for easy to read.
Summary
1
We already learn the basic JavaSript for beginner using the HomeBrew. We also using the simple ES6 ways to declare variable, let
and const
. Which is let
is used to declared variable that can be changed and const
is used to declared variable that can’t be changed. const
will be recommended because its good for project, either simple or complex one.