Do you like my tutorials?

Then consider supporting me on Ko-fi

Talking about Javascript.

If you are trying to develop HTML5 games, or any other application that uses JavaScript, sooner or later you will come across the request for installing Node.js and npm.

At that point panic usually sets in, as it all seems to be meaningless.

Why would you have to install software on your computer to use a language that until now could just be written in any text editor and then run directly in the browser?


All posts in this tutorial series:

Step 1: how to install Node.js and npm, and what to do with them

Step 2: how to set up a web server with Node.js, and why you should do it.

Step 3: using Visual Studio Code to develop HTML5 games with Phaser and webpack.

Step 4: how to publish and distribute your HTML5 games with Phaser and webpack.

Step 5: moving from JavaScript to TypeScript.


Incredibly, I know a lot of developers who have decided to give up precisely because of this seemingly insurmountable difficulty.

We’ve all been there, I’ve been there.

So now it’s time to know our enemy and turn it into our best friend.

And, believe me, you’ll wonder how you’ve been able to do without these wonderful tools for so long

Since I hate boring theory, let’s get started right away.

What is Node.js?

Node.js is an open-source, server-side JavaScript runtime environment that allows developers to build and run applications outside of a web browser.

It uses the V8 JavaScript engine, which is also used in Google Chrome, to execute JavaScript code on the server-side.

Traditionally, JavaScript was primarily used for client-side scripting in web browsers.

Node.js extends the capabilities of JavaScript by enabling it to be used for server-side programming as well.

This means that developers can write server-side applications using JavaScript, leveraging their existing knowledge of the language.

How can I know if I have Node.js installed?

Just open a command-line shell, I use PowerShell (https://github.com/PowerShell/PowerShell) and write:

node -v

This way:

If you get an error like in the image above, then you don’t have Node.js installed.

Never mind, we’ll see how to install it in a few minutes.

What is NPM?

NPM stands for “Node Package Manager”.

It is a software package manager for JavaScript programming language, primarily used with the Node.js runtime environment.

NPM allows developers to easily install, manage, and share third-party libraries, tools, and other pieces of code that can be used in their projects.

How can I know if I have NPM installed?

Just like you did for Node.js, you can check if you have NPM installed by writing on your command-line shell:

npm -v

This way:

Again, if you get an error, then you don’t have NPM installed, but we are going to remedy that right away.

And there is also good news: by installing node you will also install NPM. Two in one.

How to install Node.js

To install Node.js, go to https://nodejs.org/ and download the version compatible with your operating system.

In most cases, as the description suggests, the version “Recommended for Most Users” will be enough for you.

Once you downloaded and installed Node.js, let’s try once more to write

node -v

and

npm -v

and you will see the versions currently installed.

It’ a good practice, once you have Node.js installed, to check regularly for updates.

I have Node.js installed, what now?

Let’s create our first Node.js application.

Create a file with this JavaScript code:

JavaScript
console.log('Hello world, this is JavaScript running!');

And save it as hellonode.js.

Now navigate with your command-line shell to the folder where you saved hellonode.js and write:

node hellonode.js

And you should see Hello world, this is JavaScript running prompted in your command-line shell.

You just executed JavaScript outside a web browser.

Of course you can do many more things besides writing text on your shell, such as creating a web server.

But these are more advanced features that we will see in another post, in the meantime when you are asked to install Node.js and NPM, this is all you have to do.

Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.