Getting Started with Node.js
Tags: node, javascript, coding
Published: 2021-05-19 20:17:59

<!-- wp:paragraph -->
<p><strong>What is it all about?</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>A Back-end framework for JavaScript</li><li>It allows you to run JavaScript on the server</li><li>It's a javaScript runtime (it is not a programming language)</li><li>An extension to JavaScript</li><li>Native JSON Support</li><li>It's open source</li><li>Back-end technology</li><li>You can process multiple requests at the same time</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong>Installing</strong> <strong>Node.js</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Official Node.js Download link: <a href="https://nodejs.org/en/download/">https://nodejs.org/en/download/</a></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>LTS (Long Term Support) - Recommended for Most Users</li><li>Current - Latest features</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong>Choose an IDE</strong> <strong>(Integrated Development Environment)</strong> </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Bitesize definition of IDE from the BBC <a href="https://www.bbc.co.uk/bitesize/guides/zgmpr82">here</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Some examples of IDEs:</p>
<!-- /wp:paragraph -->

<!-- wp:group -->
<div class="wp-block-group"><div class="wp-block-group__inner-container"><!-- wp:list -->
<ul><li>Brackets</li><li>Sublime Text</li><li>Visual Studio Code</li><li>Webstorm (not free)</li></ul>
<!-- /wp:list --></div></div>
<!-- /wp:group -->

<!-- wp:paragraph -->
<p><strong>NPM (Node Package Manager)</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>An open-source package manager for Node.js created in 2009</li><li>You can import and create your own packages</li><li>A package contains all the files needed for a module</li><li>package.json.The folder node_modules is where to find the modules</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong>Creating a Simple Web Server</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>A web server </li><li>Import a package</li><li><strong>HTTP</strong>&nbsp;stands for&nbsp;<strong>H</strong>yper&nbsp;<strong>T</strong>ext&nbsp;<strong>T</strong>ransfer&nbsp;<strong>P</strong>rotocol</li><li>List of Status codes: 200/ 300/ 400/ 500...</li><li>MIME Types: Content type</li><li>HTTP request methods (GET, HEAD, POST, PUT, DELETE ...)</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong>Node.js API</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>API is the acronym for Application Programming Interface</li><li>Node.js comes with built-in packages and core modules</li><li>Index: <a href="https://nodejs.org/docs/latest/api/">https://nodejs.org/docs/latest/api/</a></li><li>To include a module, you can use <code>require()</code></li><li>File System is one example: <code>const&nbsp;fs = require('fs');</code></li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong>Terminology</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li><strong>CPU - </strong>Central Processing Unit - executes code, it's much faster than the RAM and the HD.</li><li><strong>RAM -</strong> Random Access Memory. Short-term memory</li><li><strong>HD</strong> - Hard drive. It reads the file. Long-term memory</li><li><strong>Synchronous</strong> - Program is halted until resources are available</li><li><strong>Asynchronous</strong> - The program continues executing and doesn't wait for resources to be available.</li><li><strong>Arrow notation</strong> - clean way to write a callback function</li><li><strong>Callback function - </strong>Prevents blocking, allows code to run</li><li><strong>Middleware</strong> <strong>functions</strong> - have access to the request object (req) and the response object (res). It allows isolated functionalities to interact</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong>Frameworks</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Express.js</li><li>Nest.js</li><li>Koa.js</li><li>Meteor.js</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong>Running a script</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>From the terminal type in <code>node &lt;name_of_the_file</code>.js&gt;</p>
<!-- /wp:paragraph -->