Node is an open-source runtime environment built on Javascript, it allows us to run Javascript outside the browser; Javascript was initially used inside the browser alone until node was developed. Node uses V8 which is built by Google to run javascript code in the browser. V8 takes Javascript code and compile it to machine code so that it can run on servers. In this article, I'm going to guide you through the process of setting up a node environment and creating a simple file system on your own computer using node.
Downloading and setting up a node environment.
To download node, head over to node website, the page below is displayed.
Click on the windows or mac installer according to your system's operating system in the LTS section, it is advisable to download the LTS(Long term support) version of the application than the current especially if you are a beginner. After the download has completed, follow the instructions and you have node installed on your system.
To confirm if you have node installed, go to command prompt and input the code in the image below.
This shows the version of node I have installed on my PC, As you can see from the image the version of node running on my pc is version 14.15.4 ( this might be different for you)
Let's create some cool stuffs ๐
I mentioned earlier that node allows us to run Javascript code on our computer, we are going to make use of the command line to play around with node.
From the above image, the first thing I did was to set up a node environment by typing the keyword 'node', then I performed some basic calculations using the runtime. Finally, I wrote some javascript code and we can see the result from the output.
Now let's create a file system using node
To create a file using node, we need to require the file system, then we use the writeFileSync function which will contain the file name and details expected to be in the file. If I go to the file path where this code is written I can see a txt file named mo. screenshot below.
And when I open the file I can see the text I wrote in my command prompt inside the txt file
Yaaay!!!! we have come to the end of this article. I hope you enjoy it. Kindly let me know what you think in the comment section. Cheers!