{"id":350387,"date":"2021-10-08T20:00:00","date_gmt":"2021-10-08T17:00:00","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/what-is-node-js-and-what-is-it-used-for-cloudsavvy-it\/"},"modified":"2021-10-08T20:00:00","modified_gmt":"2021-10-08T17:00:00","slug":"what-is-node-js-and-what-is-it-used-for-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/what-is-node-js-and-what-is-it-used-for-cloudsavvy-it\/","title":{"rendered":"#What Is Node.JS and What Is It Used for? \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2c753e4d1b0\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2c753e4d1b0\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/what-is-node-js-and-what-is-it-used-for-cloudsavvy-it\/#What_Is_Node\" >What Is Node?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/what-is-node-js-and-what-is-it-used-for-cloudsavvy-it\/#The_Node_Ecosystem_npm_Modules\" >The Node Ecosystem (npm Modules)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/what-is-node-js-and-what-is-it-used-for-cloudsavvy-it\/#How_Does_Node_Work_with_nginx_and_Apache\" >How Does Node Work with nginx and Apache?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/what-is-node-js-and-what-is-it-used-for-cloudsavvy-it\/#Should_I_Use_Node_for_My_Website\" >Should I Use Node for My Website?<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#What Is Node.JS and What Is It Used for? \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage imgchk9 alignnone wp-image-1112 size-full\" srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/07\/2350564e.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/07\/2350564e.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/07\/2350564e.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Node .JS\" width=\"700\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you\u2019re doing any sort of web development, you\u2019re probably going to have to learn and write Java<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">Script<\/a> at some point. Node is meant to simplify web application development by unifying the server and client side languages.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"What_Is_Node\"><\/span>What Is Node?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Node.JS, commonly referred to simply as Node, is a JavaScript runtime that allows you to run JS code outside of a web browser. Node is built on Google\u2019s V8 JavaScript engine, the same one used for processing in Chrome.<\/p>\n<p>It\u2019s commonly used for building applications, working with modern web app frameworks, and server-side scripting with JS. In practice, Node allows you to run <code>.js<\/code>\u00a0files with the <code>node<\/code>\u00a0command similar to how you would run <code>.py<\/code>\u00a0files with <code>python<\/code>:<\/p>\n<pre>node main.js<\/pre>\n<p>JavaScript code works a bit different when running in Node. First of all, there\u2019s no DOM (the loaded HTML of a webpage), so you can\u2019t access HTML elements or use a library like jQuery to much effect (though there are\u00a0<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/cheerio.js.org\/\">alternatives<\/a>). But, you have access to system resources, and can read and write files, make network connections, and even serve applications.<\/p>\n<p>Node is also used to build desktop apps, through the use of a framework called <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/electronjs.org\/\">Electron<\/a>. Electron powers Slack, Discord, Visual Studio Code, and Skype. Essentially, it runs a slimmed down version of Chrome designed for the desktop, and the app itself is actually just a web app. As a consequence though, Electron apps are very RAM hungry, and will run a bit worse than their native counterparts, but that trade is often made for uniformity across all operating systems and the web.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"The_Node_Ecosystem_npm_Modules\"><\/span>The Node Ecosystem (npm Modules)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Node itself is cool, but it wouldn\u2019t be anywhere close to where it is today if it weren\u2019t for <code>npm<\/code>, the Node package manager. <code>npm<\/code>\u00a0allows Node to be extended with frameworks and plugins, and allows code to be easily installed and incorporated into a new project.<\/p>\n<p>For example, say you\u2019re working on a script and need to make a POST request to an external resource. You could use JS\u2019s built in <code>fetch<\/code>\u00a0method, or you could use <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/axios\/axios\">axios<\/a>, which uses promises and is easier to use. If you wanted to add axios to your project, you\u2019d want to move your script to its own folder and run:<\/p>\n<pre>npm init&#13;\nnpm install axios<\/pre>\n<p>This creates a file called <code>package.json<\/code>, which keeps track of project settings and installed packages. The <code>npm install<\/code>\u00a0command will create a folder called <code>node_modules<\/code>, which stores downloaded modules. Be warned, this folder can be very large on large projects with many modules.<\/p>\n<p>To use axios in your script, you\u2019d put this line right at the top:<\/p>\n<pre>const axios = require('axios');<\/pre>\n<p>Or, in ES6 syntax:<\/p>\n<pre>import axios from 'axios';<\/pre>\n<p>This imports the module from <code>node_modules<\/code>, and allows your script to access it. From there, you can use it like it\u2019s part of your project and just another function you made.<\/p>\n<p>Axios is just a basic example of a useful <code>npm<\/code>\u00a0utility. You\u2019ve probably heard of other modules like\u00a0<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.npmjs.com\/package\/react\">React<\/a>, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/angular.io\/g\">Angular<\/a>, or <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/vuejs.org\/\">Vue<\/a>; all of these are full web application frameworks used for building interactive apps that run in the browser. Apps built with these frameworks are commonly reffered to as \u201cNode apps.\u201d While they\u2019re not actually running with Node, as the final product will be static HTML that you can serve with any old web server, Node is used for development and packages are installed from the Node ecosystem with <code>npm<\/code>.<\/p>\n<p>It\u2019s all JavaScript, after all. Often, the development code will make use of \u201cnext-gen\u201d JavaScript like ES6, and be compiled down with Webpack and Babel into one big \u201cbundle.js\u201d file that can be served to the client to run.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"How_Does_Node_Work_with_nginx_and_Apache\"><\/span>How Does Node Work with nginx and Apache?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Node itself doesn\u2019t interface directly with nginx or Apache\u2014all Node does is run <code>.js<\/code>\u00a0files. But, Node apps built with React or other frameworks do work a bit differently than normal HTML pages.<\/p>\n<p>With React, you\u2019re essentially serving a blank HTML page that loads a <code>bundle.js<\/code>\u00a0file. This bundle file works like any other javaScript file, and you can use nginx or Apache as a web server to host it. The bundle loads React, which will then render itself onto the web page and display your content. All the content is contained in the bundle file.<\/p>\n<p>One thing to note is a popular library called <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/expressjs.com\/\">Express<\/a>. Express serves web content, and can function as an HTTP server. It\u2019s commonly used as the router for making a Node-based REST API; Express can listen on a port, forward the request to another function (typically accessing another resource like a database), then send back an HTTP response.<\/p>\n<p>In this case, you\u2019d put Express behind the nginx server you use for your static content, and route all <code>\/api<\/code>\u00a0routes to Express. This allows your web app to access external resources, and make full use of Node\u2019s server side scripting power and ability to interface with databases. You can use nginx as a reverse proxy for the <code>\/api<\/code>\u00a0route, and use it as a web server for the other static content.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-1295 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/08\/3b3431f3.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\" Use nginx as a web server for other static content.\" width=\"700\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>However,\u00a0<em>Express is not a web server.<\/em>\u00a0It should not take the place of nginx in this example. It can function as one, and it\u2019s very useful to set up a simple Express server for development, or a simple page that isn\u2019t receiving much traffic. But it\u2019s a far cry from the performance of nginx and Apache, which are native apps. If you\u2019re building a real web application, serve it with nginx, and use Express only to serve APIs.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Should_I_Use_Node_for_My_Website\"><\/span>Should I Use Node for My Website?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Are you building a web app? If so, then you should seriously consider Node. Alternatives would be Ruby on Rails, Laravel with PHP, and Django with Python. But Node has the biggest community by far, and has a lot of choice when it comes to frameworks. If you don\u2019t like Ruby on Rails, you\u2019re stuck with it without learning another language, but the shift from a framework like React to Vue is much simpler, as they\u2019re both JavaScript.<\/p>\n<p>If you\u2019re not building a web app, you probably don\u2019t need Node. It\u2019s not meant for static pages. You certainly\u00a0<em>can<\/em>, but you won\u2019t see much benefit. If you\u2019re planning on using a full web framework like React for a static (or even mostly static) site, you might want to reconsider, as React introduces a lot of overhead to your site. React loading times are <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a>ly much slower without server side rendering, which is fine for web applications designed for long session durations, but not for a blog or anything looking for good SEO. Vanilla JS can do quite a bit of DOM manipulation on its own, especially with the help of jQuery.\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/1108\/what-is-node-js-and-what-is-it-used-for\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#What Is Node.JS and What Is It Used for? \u2013 CloudSavvy IT&#8221; If you\u2019re doing any sort of web development, you\u2019re probably going to have to learn and write JavaScript at some point. Node is meant to simplify web application development by unifying the server and client side languages. What Is Node? Node.JS, commonly referred&#8230;<\/p>\n","protected":false},"author":1,"featured_media":350388,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/07\/2350564e.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-350387","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/350387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=350387"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/350387\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/350388"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=350387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=350387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=350387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}