Intro to Node Js

JSNode

Sunday, March 10, 2024

What is Node?

Is a runtime for built on top of Chrome’s V8, allows you to develop apps in JavaScript outside the browser. It’s a Single threaded non blocking and asynchronous, achieved by the use of an event loop at the core of Node.

Use case:

  • API’s and servers
  • Databases (yes some DB’s are built in Node)
  • CLI’s
  • Build tools
  • Automations
  • Basic Scripting
  • GPU shopping bots

Install

which node

*Some codes work on the browser but not on node, because there a lot of features that defer from one to another.

Like the browser, node comes with some practical globals for us to use in our applications

Common

  • global, think of this as like window, but for node (DON’T ABUSE IT)
  • __dirname this global is a String value that points to the directory name of the file it’s used in
  • filename like direname, it too relative to the file it’s written in. A String value that points to the file name.
  • process A swiss army knife global. An Object that contains all the context you need about the current program being executed. Things from env vars, to what machine you’re on.
  • export module require these globals are used fro creating and exposing modules throughout your app. We’ll get to modules in a second.