curriculum/challenges/english/blocks/lecture-working-with-nodejs-and-event-driven-architecture/68ff6d2f232c60f0fa68ef86.md
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:
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 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 front-end and the back-end 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 back-end.
Which of the following best describes Node.js?
A JavaScript library used for front-end development.
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.
Think about where and how JavaScript code is executed when using Node.js.
A JavaScript framework for building user interfaces.
Think about where and how JavaScript code is executed when using Node.js.
2
Which of the following is a key difference between the browser and the Node runtime environment?
Browsers have direct access to the file system, while the Node runtime environment does not.
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.
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.
Think about the roles and purpose of each environment.
3
Which of the following tasks is Node.js commonly used for?
Manipulating the HTML structure of a web page.
Think about the server-side capabilities of Node.js.
Building a web server to handle HTTP requests.
Styling web page elements with CSS.
Think about the server-side capabilities of Node.js.
Creating interactive animations within a web browser.
Think about the server-side capabilities of Node.js.
2