In this section I’ll cover the basics of
JavaScript and Node.js.
Node.js is a runtime environment for running server-side JavaScript and we’ll be using
node.js throughout this course for all the demos and exercises.
If you are well versed with node.js, feel free to skip this section of videos, although going
through them won’t hurt.
So, let’s get started.
First, I hope you have node.js installed on your computer.
If not, please go back to the Environment Setup video from the very first section of
this course.
It explains how to install node.js on your computer.
You’ll also need a suitable text editor or IDE.
I’ll be using VS Code for all the demos in this course and you can use any text editor
or IDE of your choice.
Once you are ready, let’s continue further.
I have created a new folder on my computer
called node-training to store all our node training projects.
Let’s create another folder within this folder called hello world, hello hiphen world.
This folder would serve as our first project.
Right click and open this folder with VS Code.
If you are using any other IDE, you could simply create a new file called app.js in
this folder and open it for editing.
So, I am going to create a new file in our hello-world folder and name it as app.js
In the file, let’s type in console.log, open parenthesis and quotes, and type in Hello
World and end with a semi-colon.
Save the file.
Open the terminal or command prompt, and be sure you are in our project’s folder i.e. hello
world folder and run node space app.js i.e. node space the name of our main file.
You can skip the dot js part and simply run node space app and hit enter
And you should see Hello World printed in the output.
That was pretty easy, right?
As we move ahead in the course, the complexity would of course increase, though, I will do my best
to make even the complex stuff as easy as possible for you.
So, let’s keep going.
As I mentioned earlier, Node.js is a runtime environment for running JavaScript on the
server side.
Until before Node.js was introduced, JavaScript was only used on the client side for client-side scripting, meaning
it could run only in the web browser.
Different browsers use different engines to run JavaScript.
For example, Microsoft Edge uses Chakra, Mozilla Firefox uses SpiderMonkey, and Google Chrome
uses V8.
Node.JS simply uses Google Chrome’s implementation of JavaScript engine i.e.
the V8 engine.
And Node, of course has adapted the V8 engine to suit server-side processing.
So, some browser-specific functionality like window or the document object is not available
in Node and similarly not all Node.js functionality would be available on the on client-side in the browser
for obvious reasons of course.
To be able to work with node, we don’t really need to go in detail as to how node works.
As long as you can write JavaScript, it should be easy to write your code to run on Node.
And we’ll cover the basic JavaScript constructs as well.
So, you don’t have to worry about not knowing JavaScript.
So, let’s keep at it.
To practice Node.js, you don’t need to rely on a
text editor or an IDE.
You can even run it with a command prompt or terminal.
Let me show you what I mean.
Open up the command prompt or terminal, or you can even open PowerShell if you like and type in node
and hit enter. This would take you to node’s shell.
You can write just about any JavaScript here, just like we did in the VS Code editor and test it.
So, let’s try hello world again.
Console dot log, parenthesis, quotes, hello world, semi-colon at the end and hit enter.
And you get the same output as we got in the VS Code.
This could be handy if you have to quickly test out your script without having to create
a new JavaScript file or a new project.