feat(curriculum): add intro to node js lessons (#63084)

Co-authored-by: Kolade Chris <65571316+Ksound22@users.noreply.github.com>
This commit is contained in:
Zaira
2025-12-17 14:31:25 +05:00
committed by GitHub
parent dacf55ad1f
commit 56dec0d7bf
7 changed files with 805 additions and 4 deletions

View File

@@ -7457,6 +7457,12 @@
}
},
"blocks": {
"lecture-working-with-nodejs-and-event-driven-architecture": {
"title": "Working with NodeJS and event driven architecture",
"intro": [
"Learn about Node.js core libraries, how to install Node.js on your computer, and the advantages and disadvantages of using Node.js on the backend."
]
},
"quiz-node-js-intro": {
"title": "NodeJS Intro Quiz",
"intro": ["Test what you have learned about NodeJS in this quiz."]

View File

@@ -0,0 +1,9 @@
---
title: Introduction to the Working with NodeJS and event driven architecture
block: lecture-working-with-nodejs-and-event-driven-architecture
superBlock: back-end-development-and-apis-v9
---
## Introduction to the Working with NodeJS and event driven architecture
Learn about Node.js core libraries, how to install Node.js on your computer, and the advantages and disadvantages of using Node.js on the backend.

View File

@@ -0,0 +1,164 @@
---
id: 68ff6d2f232c60f0fa68ef86
title: What is Node and What are Some Differences Between the Browser and Node Runtime Environment?
challengeType: 19
dashedName: what-is-node-and-what-are-some-differences-between-the-browser-and-node-runtime-environment
---
# --description--
So far, you have been writing client-side code with JavaScript, code that runs on the client side of a web application, usually a web browser.
Client-side JavaScript can be very powerful, but it does have certain limitations for more complex tasks.
For example:
- It has very restricted access to local files.
- It's not really designed for handling complex application logic.
- And it has potential security concerns. For example, you would not want to expose sensitive information, such as database credentials, to client-side code.
Client-side JavaScript has these limitations because it was initially designed to run exclusively on web browsers.
Web browsers provide the environment that is needed to run JavaScript code, including the JavaScript Engine. They also provide access to the Document Object Model (DOM), so you can access HTML elements in your code.
Previously, we could not run JavaScript outside of a browser, but now we can with Node.js.
Node.js is a JavaScript runtime environment. It's officially defined as “an open-source and cross-platform JavaScript runtime environment.”
Let's see what this means:
- Node.js is open source because its code is publicly available and maintained by a large community of developers.
- It's cross-platform because it works on any operating system, including Windows, macOS, and Linux.
- And it's a JavaScript runtime environment because it allows you to run JavaScript code outside of a browser.
Node.js is used across a wide range of industries. Developers use it to build web servers and APIs that handle HTTP requests, as well as web and mobile applications.
If you are using or developing a website or web application that interacts with a database or handles complex data, there is a high chance that you will use Node.js behind the scenes at some point.
It's efficient, scalable, and it has a large community of developers and maintainers around the world.
Now that you know what Node.js is, let's see some of the differences between the browser and the Node runtime environment.
The browser environment is primarily designed for front-end web development, so it runs client-side JavaScript. In contrast, the Node runtime environment is primarily designed for back-end web development, so it runs server-side JavaScript. This also determines the APIs that they offer.
For example, from the browser, you can access the DOM API, but there are restrictions for accessing the local file system. In contrast, from the Node runtime environment, you can access almost all system resources, including the file system, but not the DOM.
Both JavaScript environments provide a global object. In the browser JavaScript runtime, this is called `window`. This `window` object provides access to browser-related functionalities, such as access to methods for manipulating the DOM, managing cookies, and handling browser events. In the Node.js environment, this global object is called `global`. The `global` object provides access to Node.js specific functionalities, such as built-in modules for working with local files, networking, and interacting with the operating system.
Finally, another important difference is that you can choose the version of Node.js that you want to use in your server. However, you have no control over the version of the browser environment that your users will use to visit your website.
Node.js has become very important for developers worldwide. It is a powerful, scalable, and versatile tool that has transformed web development by enabling developers to use JavaScript to build both the frontend and the backend of full-stack applications. This has made the development process more efficient because developers don't need to learn a new programming language just for developing the backend.
# --questions--
## --text--
Which of the following best describes Node.js?
## --answers--
A JavaScript library used for front-end development.
### --feedback--
Think about where and how JavaScript code is executed when using Node.js.
---
A JavaScript runtime environment that executes server-side JavaScript.
---
A web browser designed for running JavaScript applications.
### --feedback--
Think about where and how JavaScript code is executed when using Node.js.
---
A JavaScript framework for building user interfaces.
### --feedback--
Think about where and how JavaScript code is executed when using Node.js.
## --video-solution--
2
---
## --text--
Which of the following is a key difference between the browser and the Node runtime environment?
## --answers--
Browsers have direct access to the file system, while the Node runtime environment does not.
### --feedback--
Think about the roles and purpose of each environment.
---
The Node runtime environment uses the window object as its global object, while browsers use the global object.
### --feedback--
Think about the roles and purpose of each environment.
---
Browsers are primarily used for front-end development, while the Node runtime environment is primarily used for back-end development.
---
Browsers typically interact with the operating system, while the Node runtime environment interacts with the DOM.
### --feedback--
Think about the roles and purpose of each environment.
## --video-solution--
3
---
## --text--
Which of the following tasks is Node.js commonly used for?
## --answers--
Manipulating the HTML structure of a web page.
### --feedback--
Think about the server-side capabilities of Node.js.
---
Building a web server to handle HTTP requests.
---
Styling web page elements with CSS.
### --feedback--
Think about the server-side capabilities of Node.js.
---
Creating interactive animations within a web browser.
### --feedback--
Think about the server-side capabilities of Node.js.
## --video-solution--
2

View File

@@ -0,0 +1,152 @@
---
id: 68ff6d372ad364f285f0522e
title: What are the Advantages and Disadvantages to Using Node on the Backend?
challengeType: 19
dashedName: what-are-the-advantages-and-disadvantages-to-using-node-on-the-backend
---
# --description--
One of the great advantages of Node.js is that you can implement both the front-end and the back-end of a web application using JavaScript. This reduces the initial learning curve because you and your team don't need to learn new programming languages or switch between them as you work, so you can be more efficient and productive.
Node's architecture is another advantage. It has a non-blocking, event-driven architecture that is great for developing real-time applications, where responsiveness and efficiency are essential for creating a good user experience.
This is where the concept of “threads” becomes very important. A thread is a path of execution within a process, like a computer program that is currently running.
Node's architecture relies on a single thread and event loop that can effectively handle a large number of simultaneous requests and input/output operations. This makes it perfect for applications that require handling multiple requests simultaneously.
It also has a large community of developers around the world, who are constantly maintaining it and adding new features to it. Because of its popularity, there are many learning resources available. If you ever have a question about Node.js, it's almost guaranteed that you will find an answer, which is always helpful.
When you work with Node.js, you also have access to `npm`, a package manager for Node.js. `npm` is a powerful tool that allows you to install and manage packages and modules for your projects.
You'll find packages for many different purposes, including handling HTTP requests, working with databases, formatting dates and times, testing code, and more. By using packages, you can reuse code that was already written, tested, and shared by other developers to make your workflow faster and more efficient.
And finally, in terms of costs, Node.js has the great advantage of being free and open source. Its packages, libraries, and associated tools are also primarily free. This can be an important factor when considering how to optimize your budget.
On the other hand, Node.js does have certain disadvantages or limitations that you should be aware of.
As you learned, it only runs one thread at a time, which means that it can only handle one operation at a time. While its architecture allows it to be efficient for handling concurrent (simultaneous) requests, CPU-intensive tasks may block the main thread and result in performance issues.
Examples of CPU-intensive tasks include complex mathematical operations, image and video processing, and cryptography. There are ways to overcome this, but they usually increase the complexity of the application.
Node.js also relies on asynchronous programming. In asynchronous programming, a task that may take a long time to run is started, but instead of waiting until it's completed, the main program continues running while the asynchronous task runs in parallel. When the task is completed, the program handles the result.
This process often involves what we know as “callbacks,” which are functions that define what happens when the asynchronous operations are completed. The asynchronous nature of Node.js can potentially make the code more difficult to read, understand, and debug.
And finally, you should also be careful when choosing packages from `npm`, the Node package manager, because some of them may not be constantly maintained, so they may introduce vulnerabilities into your own application. As a developer, you should evaluate each package carefully and check if it follows quality and security best practices.
Node.js is currently one of the most popular tools for developing web applications. Knowing its advantages and disadvantages will help you to determine if it's the right tool for your project.
# --questions--
## --text--
Which of the following is an advantage of using Node.js for back-end development?
## --answers--
It is very efficient for CPU-intensive tasks due to its multi-threaded architecture.
### --feedback--
Think about the programming language used by Node.js.
---
It allows developers to use JavaScript for both front-end and back-end development.
---
It avoids asynchronous programming, making code easier to read and maintain.
### --feedback--
Think about the programming language used by Node.js.
---
It has a small and inactive community, limiting available resources and support.
### --feedback--
Think about the programming language used by Node.js.
## --video-solution--
2
---
## --text--
Which of the following is a potential disadvantage of using Node.js for back-end development?
## --answers--
Its non-blocking architecture makes it inefficient for handling multiple concurrent requests.
### --feedback--
Think about how Node.js handles tasks.
---
The large and active community can make it difficult to find reliable packages.
### --feedback--
Think about how Node.js handles tasks.
---
Its single-threaded nature can reduce the efficiency of CPU-intensive operations.
---
The use of JavaScript for both front-end and back-end can lead to inconsistencies.
### --feedback--
Think about how Node.js handles tasks.
## --video-solution--
3
---
## --text--
Node.js's strengths make it particularly well-suited for which of the following?
## --answers--
Applications with complex mathematical algorithms.
### --feedback--
Think about what Node.js is designed to handle efficiently.
---
Applications that require handling high concurrency and real-time updates.
---
Applications with complex relational database interactions.
### --feedback--
Think about what Node.js is designed to handle efficiently.
---
Applications where development speed is not a major factor.
### --feedback--
Think about what Node.js is designed to handle efficiently.
## --video-solution--
2

View File

@@ -0,0 +1,433 @@
---
id: 68ff6d39d7ed9ef36ff281f3
title: How can you Install Node on your Computer?
challengeType: 19
dashedName: how-can-you-install-node-on-your-computer
---
# --description--
Now you're ready to take your first steps into the world of Node.js by installing it on your computer. But first, before you install Node.js, we recommend installing a tool called NVM (Node Version Manager). As its name implies, NVM is a tool for managing multiple versions of Node.js on the same computer.
Setting up this tool from the start will help you in the future because you might need to switch between different versions of Node.js for different projects. With NVM, you can do this very easily.
Let's see how you can install NVM on macOS/Linux and Windows, and how you can use it to install Node.js.
## How to Install NVM on macOS/Linux
On macOS and Linux, you can install NVM directly through a shell script.
But for macOS, note that the official documentation for NVM mentions that “you need to manually install the Xcode command line tools before running the install script, otherwise, it'll fail.”
On macOS, you can install Xcode command line tools by running this command in your terminal:
```bash
xcode-select --install
```
Once the installation is finished, you can check the version number and verify the installation with this command:
```bash
xcode-select --version
```
Then, it's time to install NVM. You can download and execute the NVM installation script by running one of these commands:
```bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
```
```bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
```
To get the latest version of NVM at the time when you are reading this article, please refer to the official NVM documentation: `https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script`. There, you will find these commands with the latest version number.
You might need to restart your terminal when the process is completed to load the new command and the new configuration.
Then, run this command to confirm that NVM was installed correctly and to check your current version:
```bash
nvm -v
```
You should see your version of NVM in the output.
## How to install Node.js with NVM on macOS/Linux
Now that you have NVM installed on macOS/Linux, you can install Node.js.
To install the latest Long-Term Support (LTS) version of Node.js, run this command:
```bash
nvm install --lts
```
Notice the `--lts` flag. This flag indicates that you want to install the current Long-Term Support (LTS) version of Node.js. This version is usually recommended because it prioritizes stability, reliability, and security over new or experimental features. It is thoroughly tested and ready for production. It's also guaranteed to have longer support periods with a focus on bug fixes and security patches.
Alternatively, you can install a specific version of Node.js by specifying the version number in the command:
```bash
nvm install <version>
```
For example, here's how you can install Node.js v20:
```bash
nvm install 20
```
Once you finish installing a version of Node.js, you can switch to that version with this command:
```bash
nvm use <version>
```
For example, here's how to switch to version 20:
```bash
nvm use 20
```
Finally, you can check the current version of Node.js with this command:
```bash
node -v
```
## How to install NVM on Windows
Now let's see how you can install and use NVM on Windows.
Official versions of NVM only support Windows in specific cases. If you have Windows Subsystem for Linux (WSL) set up on your device, you can follow the macOS/Linux guide above to install and use NVM.
However, for Windows itself, there are a few alternatives. One of them is `nvm-windows`, a Node.js version management utility for Windows. This is a completely separate project from the official NVM project. But the purpose of these tools is the same — to help you work with multiple versions of Node.js on the same device.
Before installing `nvm-windows`, you should know that the official repository recommends uninstalling any prior Node installation before installing NVM for Windows. If this is your first time installing Node.js, you should be okay. If you already have other versions of Node.js installed, it is recommended to uninstall them first.
To install `nvm-windows`:
- Go to the Releases section of the official repository: `https://github.com/coreybutler/nvm-windows/releases`.
- Download the latest installer.
- Follow the instructions.
After completing the installation, you might need to restart your terminal if the `nvm` command is not immediately available.
You can check if the installation was successful and see your current version of `nvm-windows` by running this command:
```powershell
nvm -v
```
## How to Install Node.js using NVM for Windows
Now that you have `nvm-windows` installed on Windows, you are ready to install Node.js.
To install the latest Long-Term Support (LTS) version of Node.js, run this command:
```powershell
nvm install lts
```
The Long-Term Support (LTS) version is usually recommended, but you can install a different version by specifying its version number in the command:
```powershell
nvm install <version>
```
For example:
```powershell
nvm install 20
```
When the installation is completed, you can switch to that version of Node.js with this command:
```powershell
nvm use <version>
```
For example:
```powershell
nvm use 20
```
You can also check your current version of Node.js with this command:
```bash
node -v
```
## Basic Commands
Now that you know how to install NVM and Node.js, let's check out some basic commands that you will find helpful when working with Node.js and NVM.
Also, while all these commands will work for NVM installed on macOS/Linux, including WSL, they may work differently or may not work at all for `nvm-windows`. We'll leave alternative commands for `nvm-windows` whenever possible.
### How to Adjust Powershell's Execution Policy
If you're running Windows and are following along with Powershell and `nvm-windows`, you may need to adjust Powershell's execution policy. The default execution policy for Powershell is `Restricted`, which is a security measure to prevent scripts from running.
First, run Powershell as an administrator by right-clicking on Powershell, then clicking “Run as Administrator“.
Then, to see the current execution policy of the current Powershell session, run the following command:
```powershell
Get-ExecutionPolicy
```
Finally, to set Powershell's execution policy to `RemoteSigned`, which allows local scripts and `npm` to run, use the following command:
```powershell
Set-ExecutionPolicy RemoteSigned
```
Once you've run the command above, you can close the administrator window of Powershell, and open a non-admin Powershell window.
### List All Versions
To list all installed versions of Node.js and check the one that is currently being used, run this command:
```bash
nvm ls
```
### Set Default Node.js Version (NVM on macOS/Linux Only)
This command sets the default version of Node.js that will be used for new terminal sessions:
```bash
nvm alias default <version>
```
For example:
```bash
nvm alias default 22.20.0
```
You can also create custom aliases to assign a more specific name to a version:
```bash
nvm alias <new_name> <version>
```
For example:
```bash
nvm alias new-api 18.20.8
```
After setting up the alias, you can use this new name to switch to that version:
```bash
nvm use <new_name>
```
For example:
```bash
nvm use new-api
```
### Remove a Version of Node.js
To remove a version of Node.js, run this command:
```bash
nvm uninstall <version>
```
For example:
```bash
nvm uninstall 20.19.5
```
With NVM for macOS/Linux, you can remove a version of Node.js by running the `uninstall` command with a major version like `22` or `20`. For example:
```bash
nvm uninstall 20
```
If you have multiple releases for that major version installed like `20.14.0` and `20.12.2`, the latest version will be removed first. In this case, running `nvm uninstall 20` will remove `20.14.0` first.
### Check Your Version of Node.js
To check your current version of Node.js, you can use the following:
```bash
node -v
```
### Check Your Version of npm
`npm` is a package manager for Node.js. You can use it to install, publish, and manage software packages. It is automatically installed when you install Node.js.
To check your current version of `npm`, run this command:
```bash
npm -v
```
### Run a JavaScript File
This command runs the JavaScript file that you specify in the currently active Node.js runtime:
```bash
node <file.js>
```
For example:
```bash
node app.js
```
### Create a Node.js Project
This command creates a new Node.js project by creating a `package.json` file that tracks its details and dependencies.
```bash
npm init
```
When you run the `npm init` command, it will walk you through an interactive CLI guide for setting up the `package.json` file. It will ask you questions for the project name, description, version, etc. If you want to start with a default `package.json` file, you can use the `npm init -y` or `npm init --yes` command.
### Install a Package
To install a specific package, run:
```bash
npm install <package>
```
For example:
```bash
npm install express
```
### Install Dependencies
To install all the dependencies listed in the `package.json` file of a project, run:
```bash
npm install
```
# --questions--
## --text--
What is the primary reason for using `nvm` (Node Version Manager) or `nvm-windows`?
## --answers--
To install `npm` packages globally.
### --feedback--
Think about the "V" in "NVM" and what "manager" implies for software.
---
To execute Node.js scripts in the browser.
### --feedback--
Think about the "V" in "NVM" and what "manager" implies for software.
---
To manage and switch between multiple Node.js versions.
---
To debug Node.js applications efficiently.
### --feedback--
Think about the "V" in "NVM" and what "manager" implies for software.
## --video-solution--
3
---
## --text--
Which `nvm` command would a developer use to switch their current terminal session to a specific installed Node.js version, for example, version `18.17.1`?
## --answers--
`nvm set 18.17.1`
### --feedback--
Think about the verb used by `nvm` to indicate which version should be active for the current shell.
---
`nvm switch 18.17.1`
### --feedback--
Think about the verb used by `nvm` to indicate which version should be active for the current shell.
---
`nvm select 18.17.1`
### --feedback--
Think about the verb used by `nvm` to indicate which version should be active for the current shell.
---
`nvm use 18.17.1`
## --video-solution--
4
---
## --text--
A new Node.js project needs to be initialized, setting up the `package.json` file to manage its dependencies and scripts. Which command is used for this purpose?
## --answers--
`npm init`
---
`npm start`
### --feedback--
The command needs to create the project's foundational file for package management.
---
`node init`
### --feedback--
The command needs to create the project's foundational file for package management.
---
`npm install`
### --feedback--
The command needs to create the project's foundational file for package management.
## --video-solution--
1

View File

@@ -0,0 +1,22 @@
{
"name": "Working with NodeJS and event driven architecture",
"isUpcomingChange": true,
"dashedName": "lecture-working-with-nodejs-and-event-driven-architecture",
"helpCategory": "Backend Development",
"blockLayout": "challenge-list",
"challengeOrder": [
{
"id": "68ff6d2f232c60f0fa68ef86",
"title": "What is Node and What are Some Differences Between the Browser and Node Runtime Environment?"
},
{
"id": "68ff6d372ad364f285f0522e",
"title": "What are the Advantages and Disadvantages to Using Node on the Backend?"
},
{
"id": "68ff6d39d7ed9ef36ff281f3",
"title": "How can you Install Node on your Computer?"
}
],
"blockLabel": "lecture"
}

View File

@@ -7,7 +7,10 @@
{
"dashedName": "introduction-to-nodejs",
"comingSoon": true,
"blocks": ["quiz-node-js-intro"]
"blocks": [
"lecture-working-with-nodejs-and-event-driven-architecture",
"quiz-node-js-intro"
]
},
{
"dashedName": "nodejs-core-libraries",
@@ -44,14 +47,26 @@
"comingSoon": true,
"blocks": []
},
{ "dashedName": "websockets", "comingSoon": true, "blocks": [] },
{ "dashedName": "node-and-sql", "comingSoon": true, "blocks": [] },
{
"dashedName": "websockets",
"comingSoon": true,
"blocks": []
},
{
"dashedName": "node-and-sql",
"comingSoon": true,
"blocks": []
},
{
"dashedName": "security-and-privacy",
"comingSoon": true,
"blocks": []
},
{ "dashedName": "authentication", "comingSoon": true, "blocks": [] },
{
"dashedName": "authentication",
"comingSoon": true,
"blocks": []
},
{
"dashedName": "tooling-and-deployment",
"comingSoon": true,