Today was another sunny day, I and my husband had a fun time basking in sun and enjoying food and drinks 😋
I am not able to find time to put regular updates on Medium, if you are curious and interested in following what I am learning each day, please feel free to check 😁
The Journey of #100DaysOfCode (@henna_dev)
Hello Everyone, 👋 I had heard a lot on #100DaysOfCode and really wanted to work together with friends on this. I would…
I am also excited to share that we would be organizing our very first Dublin MongoDB user-group event on April 27, 2022. If you are around Dublin, you are more than welcome to join us 🤗
Dublin MUG: Let's talk Atlas, Realm and MongoDB Queries
G'Day, Folks, 👋 It's great to know we are now starting to get back to normal and more exciting things have started…
Let’s head over to Runtime environments, it was new information for me.
What is a Runtime Environment?
A runtime environment is where the program is executed. It determines what global objects a program can access and it can also impact how it runs. Today I am writing about two environments
- A browser (Chrome, or Firefox) runtime environment
- The Node runtime environment
A Browser’s Runtime Environment
website.htmlwith some code inside can be created on the computer:
<!-- website.html -->
<h1> Random Website </h1>
<script> window.alert('Hello World'); </script>
This file can be saved and opened in a browser. Upon loading, the embedded
<script></script> executes and the
window.alert() method creates a pop-up box in the browser with the text “Hello World”.
Now the question pops: Where did the
window.alert() method comes from and how can it control the browser?
This is because the code is getting executed in the browser’s runtime environment. The
window.alert() method is built into this environment and any program executed in a browser has access to this method. In fact, the window object provides access to a huge amount of data and functionality relating to the open browser window beyond just
Applications created for and executed in the browser are known as front-end applications.
The Node Runtime Environment
Node is an entirely different runtime environment, meaning that browser-environment data values and functions, like
window.alert(), can’t be used.
Instead, the Node runtime environment gives back-end applications access to a variety of features unavailable in a browser, such as access to the server’s file system, database, and network.
For example, it's easy to check the directory of a file name myApp.js using the Node runtime environment variable
process.env is an object containing environment variables such as
process.env.PWD which contains the current working directory (and stands for “Print Working Directory”).
$ node myApp.js
node command tells the computer to execute the
myApp.js file in the Node environment. The
node command can also be used without a file argument to open up the Node Read-Eval-Print-Loop (REPL):
- a browser’s runtime environment
- the Node runtime environment
In each of these environments, different data values and functions are available, and these differences help distinguish front-end applications from back-end applications.