How to use Node.js

If you visit the Node.js website, the homepage will briefly describe the two major uses for Nodejs. The first major use is that JavaScript can be ran outside the browser. The second major use is that Nodejs has NPM, which is a very popular JavaScript package manager.

Before I began using Node.js, NuGet Manager within Visual Studio was my primary source for downloading JavaScript packages for my projects. There are so many JavaScript frameworks available now, Node.js becomes the central repository (node) for retrieving the frameworks. Instead of going to individual websites to download JavaScript frameworks, Node.js retrieves all the files for the requested framework with one command.

Node.js is very easy to use and I'll walk through a few commands.

After install the latest version of Node.js, open the command prompt and install jQuery. With Node.js, install actually means copy. Node.js will install(copy) JavaScript frameworks on the computer.

Since I installed a new copy of Node.js on my computer, my jquery install failed. This happened because Node.js does not know where to save the files on the computer.

Node.js needs package.json file. To create the file, first run this command: npm --version

Next, run the command to
the express install: npm install express

Finally, run the command to
initialize the package.json: npm init -y

To verify where package.json was installed, go to the directory listed in the command prompt. node_modules and package.json should be available as shown in the picture below:

If you open the folder node_modules, there will be over 40 folders. To install the latest jquery framework, try the command again: npm install jquery. Node.js knows where to install the requested JavaScript frameworks.

Now I can install the latest version of AngularJS with this command: npm install angular.

And I'll install the latest version of TypeScript with this command: npm install typescript.

Less than one minute, Node.js was able to install all three of these popular frameworks without me visiting their respective websites or without me using NuGet Package Manager.

As for the other major feature with Node.js, let's run a javascript file outside of a browser (Chrome, IE, Mozilla). Within my C:\Users\JoshY folder, I created a JavaScript file named: javascript.js

To execute JavaScript file in Node.js, type the following command:node javascript.js

There was a javascript syntax error.
I modify javascript.js with the correct syntax and type the following command:node javascript.js

In summary, this was a basic introduction of why Node.js has become a very popular and powerful tool for developers. Web development has become scattered with JavaScript frameworks in the thousands. Eventually, JavaScript become like nailing jello to a tree and I needed Node.js to become a node for all JavaScript packages. No more web searching for JavaScript frameworks. A quick visit to the NPM website for the simple commands for the latest JavaScript packages I want for my projects.

Please fill free to leave comments below:

Software Solutions

We want to get involved