<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rakshith</title>
    <description>The latest articles on DEV Community by Rakshith (@rakshith_2209).</description>
    <link>https://dev.to/rakshith_2209</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F382043%2Fbbdebc3c-de85-4c1f-a392-502a8f957391.jpg</url>
      <title>DEV Community: Rakshith</title>
      <link>https://dev.to/rakshith_2209</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rakshith_2209"/>
    <language>en</language>
    <item>
      <title>Incorporating NodeJs </title>
      <dc:creator>Rakshith</dc:creator>
      <pubDate>Thu, 04 Jun 2020 05:01:43 +0000</pubDate>
      <link>https://dev.to/rakshith_2209/implementing-nodejs-314c</link>
      <guid>https://dev.to/rakshith_2209/implementing-nodejs-314c</guid>
      <description>&lt;h2&gt;
  
  
  &lt;em&gt;Introduction&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.Node.js was written initially by Ryan Dahl in 2009, about thirteen years after the introduction of the first server-side JavaScript environment, Netscape's LiveWire Pro Web.Node.js is an open-source, cross-platform runtime environment for developing server-side and networking applications. Node.js applications are written in JavaScript and can be run within the Node.js runtime on OS X, Microsoft Windows, and Linux. Node.js also provides a rich library of various JavaScript modules which simplifies the development of web applications using Node.js to a great extent. Because of its superfast capabilities, it has been successful in attracting corporate clients like IBM, LinkedIn, and many other giants in the industry.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;Lets get Started Shall we?&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;In this post, we will take a look at how you would be able to incorporate Node.js into your Web Application. You are going to learn the usage of this from scratch as well as take a look at an example.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;Prerequisites&lt;/em&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;a Web browser such as Chrome.&lt;/li&gt;
&lt;li&gt;Node.js above 12.x.x&lt;/li&gt;
&lt;li&gt;Basics of JavaScript&lt;/li&gt;
&lt;li&gt;NPM install.&lt;/li&gt;
&lt;li&gt;Terminal ( I am using Hyper terminal in this post )&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you install Node it already comes with a bunch of modules. In this post we will take a look at one such built-in module and also we would take a look at how to incorporate external modules. We can use Node to get access to the local files of the computer too.&lt;br&gt;
The link provided here takes us to the official Node.js File System Documentation page..&lt;br&gt;
(&lt;a href="https://nodejs.org/api/fs.html" rel="noopener noreferrer"&gt;https://nodejs.org/api/fs.html&lt;/a&gt;)&lt;br&gt;
To illustrate the fact that Node can be used to manipulate the file-systems of your machine we will be taking a look at a method called copyFileSync() which copies the content from one file to the other.&lt;br&gt;
Start with creating a folder called "introduction-to-node" , and creating a Javascript File.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fumn7phqd7mx9xx4uxq06.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fumn7phqd7mx9xx4uxq06.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to use the modules we first need to &lt;em&gt;require&lt;/em&gt; the module. Now also create a simple text file called "file1.txt". Now write any sentence you like... &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F00u58xtxh6vd0mllkkym.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F00u58xtxh6vd0mllkkym.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fileSystem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// "fileSystem" is our constant and "fs" is the module.&lt;/span&gt;
&lt;span class="nx"&gt;fileSystem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;copyFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;file1.txt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;file2.txt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;implement the same by typing "node index.js" &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff9axnertowt6n6fekhxd.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff9axnertowt6n6fekhxd.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see we have successfully implemented the file System Module and we have achieved the target of copying contents of one text file to the other. (ie from file1.txt to file2.txt)&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;How to incorporte external modules using NPM?&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;NPM stands for Node Package Manager and it’s currently the world's largest collection of packages. Using NPM we could incorporate packages inside your projects saving us time and energy. Make sure that you are in the working directory. Now we are going to initialize NPM here by saying "npm init -y".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8i4om7uwoqs1xgk1vo10.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8i4om7uwoqs1xgk1vo10.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we will try to install a sample package called "animals" and try experimenting with it.&lt;br&gt;
The link to the same is provided here. (&lt;a href="https://www.npmjs.com/package/animals" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/animals&lt;/a&gt;).&lt;br&gt;
We will accomplish this in a very systematic step by step procedure as shown below:-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new folder.&lt;/li&gt;
&lt;li&gt;Create a new JavaScript file.&lt;/li&gt;
&lt;li&gt;Using Hyper Terminal initialize NPM.&lt;/li&gt;
&lt;li&gt;Install the sample "animal" package by typing "npm install animals"&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F74i110aiblu1t73ryt7e.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F74i110aiblu1t73ryt7e.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now with that in place, we can verify that we have successfully installed the required packages by looking at our dependencies in our package.json file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4g5oxw4bb3meckk5ou5m.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4g5oxw4bb3meckk5ou5m.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this simple illustration we will try logging the names of animals in the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;animals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;animals&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;animal1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;animals&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// animal1 stores a name of an amimal&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;animal2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;animals&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// animal2 stores a name of an amimal&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Name of my first animal is:  &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;animal1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Name of my second animal is:  &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;animal2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now just test your output using the Hyper Terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwdu7pwhiru3k31cys4i3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwdu7pwhiru3k31cys4i3.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;Conclusion&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;I hope in this post you get the idea of how to work with Node Packages and incorporate any external modules too.&lt;/p&gt;

&lt;p&gt;Link to my twitter: (&lt;a href="https://twitter.com/rakshith_2209?lang=en" rel="noopener noreferrer"&gt;https://twitter.com/rakshith_2209?lang=en&lt;/a&gt;)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>javascript</category>
      <category>node</category>
    </item>
  </channel>
</rss>
