Hướng dẫn thử thách
1 / 3
What Is Node and What Are Some Differences Between the Browser and Node Runtime Environment?
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.
For a long time, JavaScript was used almost exclusively inside browsers, but with Node.js you can run it outside a browser too.
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.
The `globalThis` object can be used to access the global object in both browser and Node.js environments. In the browser JavaScript runtime, the global object is also available through `window`. This `window` object provides access to browser-related functionalities, such as methods for manipulating the DOM, managing cookies, and handling browser events. In the Node.js environment, the global object is also available through `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. However, Node.js marks `global` as a legacy API and recommends using `globalThis` instead.
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.
Vượt qua bài kiểm tra hiện tại để mở khóa bài tiếp theo.
main.sql
UTF-8 • Tab Size: 2Kiểm tra bài:⌘↵