{"componentChunkName":"component---src-templates-blog-post-js","path":"/5-things-you-probably-dont-know-about-node-js","result":{"data":{"contentfulBlogPost":{"createdAt":"2019-09-11T19:24:49.166Z","updatedAt":"2019-09-14T00:10:50.935Z","id":"3dede988-0445-5af7-b64f-24eefd249d81","description":"Are you sure you are not an average Node.js Developer?","title":"5 things you probably don't know about Node.js","body":{"id":"e82d241c-5604-582c-aa37-c07138d36702","childMarkdownRemark":{"id":"268157d6-2b84-5d0f-97e2-e36f8c0fb49b","html":"<p>A few days ago, i was reading an article about how works Node.js child process and how the main process keep running in one core. After that, I stared to dig deeper in the Node.js repo to learning more about its internal behavior. These type of things, are the things you‘ll never find in an online course.\nThat's why today i'm writing this post. </p>\n<p>Most learning resources available on the internet (specially the online courses) about Node.js always teach about external packages and not about its runtime environment. The developers who are satisfied just with those resources, <em>let’s consider them hypothetically “average”</em>.</p>\n<p>Now, we will learn about some tricky things about Node itself, which level up our proficiency with this ecosystem.</p>\n<h2>The CallStack is part of V8 Engine</h2>\n<p>Yes, it is. The V8 uses the Callstack as part of its architecture to keep the track of the functions invocations. So, what is the CallStack? It’s a data structure that records all the function calls, every time we invoke a function it take a references and keep doing so for each nested others invocation, including those who makes recursion.</p>\n<p><img src=\"https://i.ytimg.com/vi/2ZH_1d8TYVg/maxresdefault.jpg\" alt=\"From &#x22;Philip Roberts: What the heck is the event loop anyway&#x22; at JSConf EU \"></p>\n<p>Is important to keep the Callstack not too much busy because there are just one CallStack available per Node process. Moreover, it just pop the nested function when this one finish and return a value.</p>\n<h2>So, The Event Loop is inside V8 too?</h2>\n<p>No. The event loop is provide by the libuv library. It is in charge to handle the external events who need of <strong>Node API</strong>, picking from event queues and push their callbacks into the Callstack.\nIt acts like a guide, with functions like <strong><em>setTimeout</em></strong> or <strong><em>fs.readFile</em></strong> that belong to Node API, not to Javascript. It also decide what to execute next in the CallStack when is empty.</p>\n<p><img src=\"https://miro.medium.com/max/700/1*xm_WajiPlaOeJWcqgJb1xQ.png\" alt=\"Node.js event loop architecture - Andranik Keshishyan\"></p>\n<h2>Why Node.js exit?</h2>\n<p>When a Node program runs, It will start the event loop automatically, and keep iterating while there something in execution, So, when the Call Stack and the Event Loop don’t have nothing else to do, the process exit.\nNode keep the process running when you start a timer or an HTTP server.</p>\n<h2>Node external dependencies</h2>\n<p><img src=\"http://p0.qhimg.com/t0157e547f53940dfd6.png\" alt=\"https://www.zcfy.cc/original/architecture-of-node-js-internal-codebase-506.html\"></p>\n<p>The node.js environment has a few libraries to help of the low-level operations of javascript. These are the libraries we have available:</p>\n<ul>\n<li><strong>libuv</strong></li>\n<li><strong>http-parser</strong></li>\n<li><strong>c-ares</strong></li>\n<li><strong>OpenSSL (crypto)</strong></li>\n<li><strong>Zlib</strong></li>\n</ul>\n<p>All of them are external to Node. They have their own source code. They have their own license. Node just uses them.\nIs good to learn this point, to be fair and not blame everything on Node ;).</p>\n<h2>Node.js could be used without V8</h2>\n<p>Node.js require a VM to run the main process but it is not necessarily V8. V8 is Google’s open source project not originally build by the node.js team. It’s not very common but You can use Chakra instead.</p>\n<p><a href=\"https://github.com/nodejs/node-chakracore\">View Chakra repo on Github</a></p>\n<h2>Circular module dependencies are allowed</h2>\n<p>If you have two modules who require each other, <em>will throw an error?</em> Well no.\nIn these cases, you will warned because when the circular require loop start, the first file will not be done yet, so the second file just will render as a partial version.</p>\n<pre><code class=\"language-javascript\">// module1.js\n\nrequire(\"./module2\")\n\n\n\n\n// module2.js\n\nrequire(\"./module1\");\n</code></pre>\n<hr>\n<p>I hope you have learn new things and they can help you in your journey working with this amazing environment.</p>\n<p>If you felt exiting about these type of topics, let me know with a comment.</p>","excerpt":"A few days ago, i was reading an article about how works Node.js child process and how the main process keep running in one core. After that, I stared to dig deeper in the Node.js repo to learning more about its internal behavior. These type of things, are the things you‘ll never…"}},"image":{"id":"c1556ccc-453f-5f10-ab80-a39fa3e6e282","fluid":{"base64":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAALABQDASIAAhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAAYIA//EACsQAAECBQIEBQUAAAAAAAAAAAECAwAEBQYRITEHExVBEiI1RVFxkrHR0v/EABUBAQEAAAAAAAAAAAAAAAAAAAUG/8QAIxEAAgEDBAEFAAAAAAAAAAAAAQIDAAQRBhIiMQchkaGi0f/aAAwDAQACEQMRAD8Aba1erD1HkrTptXE3bjQDyuoUqWl3WHt1KC0latcDKvFkjynI3Xp6akaDVKQ9IzlNrLiTzXpblh1rTOAvsQSNRn47ERHKOJtzocCk1d0KzuEIz+I1PFa7D7099iP1Cr6gSW5jucugQnKK3F/XtsFRk9Hian7fS11DYT2kixSO+NrsCWjwAAE3KxwOwAw7qy7ktekXFUeqLqNtNOziEvOS0tLvtol1HdsJLWmN8JJTrppBEYK4qXXn1l4fRCP5gh+PWcIUAxN9T87al38fXjMWMqe7/tf/2Q==","aspectRatio":1.7777777777777777,"src":"//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=786&q=50","srcSet":"//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=197&h=111&q=50 197w,\n//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=393&h=221&q=50 393w,\n//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=786&h=442&q=50 786w,\n//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=1179&h=663&q=50 1179w,\n//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=1572&h=884&q=50 1572w,\n//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=1920&h=1080&q=50 1920w","srcWebp":"//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=786&q=50&fm=webp","srcSetWebp":"//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=197&h=111&q=50&fm=webp 197w,\n//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=393&h=221&q=50&fm=webp 393w,\n//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=786&h=442&q=50&fm=webp 786w,\n//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=1179&h=663&q=50&fm=webp 1179w,\n//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=1572&h=884&q=50&fm=webp 1572w,\n//images.ctfassets.net/szbztvipepx3/6Mkbzl9DAw7qdeaiWXv1fB/e750ccd7c622aab8df282eb02bf04307/level.jpg?w=1920&h=1080&q=50&fm=webp 1920w","sizes":"(max-width: 786px) 100vw, 786px"}}}},"pageContext":{"slug":"5-things-you-probably-dont-know-about-node-js","intl":{"language":"en","languages":["en","es"],"messages":{"title":"Omar Gaston","navbar.knowme":"About me","navbar.projects":"Projects","navbar.contact":"Contacts","frontpage.readMyBlog":"Read my blog","frontpage.knowme":"Who am I?","blog.subtitle":"Creating stories.","blog.title":"Sharing my ideas","blog.text":"with the community.","subscribe":"Subscribe","changeLanguage":"ES","goBack":"Go back","viewOnGithub":"View on Github","viewProject":"View Project","viewMore":"See more","notFound.title":"NOT FOUND","notFound.text":"You just hit a route that doesn't exist... what sadness! ","notFound.knowAuthor":"well, this guy","notFound.goBlog":"Better go and read something","notFound.whoSay":"...Who say that?","personal.title":"Who I Am?","personal.fullname":"Omar Gaston Chalas","personal.salute":"Hi, I'm","personal.presentation":"A Javascript Full-Stack Developer, Lover of creating products which make people's life easier.","personal.presentationContinue":"I'm always eager to hear about new ideas, create and learn new things.","personal.coverletter":"Well I'm Omar, a Dominican Software Engineer passionate about Javascript, web development and related technologies. As a developer, I've been building highly scalable business apps for more than 3+ years caring deeply about the details in both well-crafted code and user-facing experience. ","personal.coverletterContinue":"Since I remember, I've always been curious and eager to learn new technologies and acquire new skills. Constant learning and a proactivity attitude have allowed me to be comfortable with the rapid changes which are already common in the modern tech industry.","personal.coverletterContinue2":"Despite I care about keeping my technical skills shaped, I also have a Startup mindset and pragmatic attitude, that comes with a willingness to lead projects and desire to understand about the business and where it’s heading","personal.quote":"It's not all about me, As a team player, I love collaborating with others and be involved in Open Source projects. For me, mentoring and helping others is the best way to giving back to those whos have led me in the past.","personal.coverletterFooter":"By the way, These are some of the tools I'm currently using: ","aptitudes.title":"Skills","aptitudes.creativity.title":"Creativity","aptitudes.creativity.text":"The best way to demonstrate authenticity is by being creative.","aptitudes.innovation.title":"Innovation","aptitudes.innovation.text":"Experiment and apply new technologies.","aptitudes.focused.title":"Focus","aptitudes.focused.text":"The correct solutions arise by dividing a problem and focusing on each part.","aptitudes.consistency.title":"Consistency","aptitudes.consistency.text":"The only way to achieve success is to persevere.","aptitudes.simplest.title":"Simplicity","aptitudes.simplest.text":"It's always good when something works, but when it's simple and works, it's wonderful.","aptitudes.community.title":"♥","aptitudes.community.text":"Work as a team with communities and colleagues.","projects.title":"Projects","projects.text":"Some of the projects I've been working on","contact.title":"Contact","contact.text":"Talk to me and work together.","contact.form.email.label":"Email","contact.form.email.placeholder":"Your email","contact.form.message.label":"Message","contact.form.message.placeholder":"Anything about you, your work or your pet :)","contact.form.submit":"Send","contact.form.secondmessage":"Tell me, what's going on?","contact.writeme":"Write me!","lastPost.title":"Latest posts","search.result":"result","search.noresult":"No results for","search.search":"Search"},"routed":false,"originalPath":"/5-things-you-probably-dont-know-about-node-js","redirect":false}}}}