Learn about nodejs (P2)

Tram Ho

Use effective documentation

Homepage https://nodejs.org/en/docs/

As you can see on the left, nodejs applies the features of ES6. Excerpt from the homepage of nodejs

Node.js is built on modern versions of V8. By updating the latest releases of this tool, we ensure new features from the ECMA-262 JavaScript specification are brought to Node.js developers in a timely manner, as well as continuing to improve. Improve performance and stability.

All ECMAScript 2015 (ES6) features are divided into three groups: shipping , staged , and in progress :

All shipping features, which are considered stable by V8, are enabled by default on Node.js. Staged features, which are almost complete features that the V8 team does not consider stable, require runtime flags: –harmony. In progress features can be individually enabled by their respective harmony flags, although this is not recommended unless for testing purposes. Note: these flags are displayed by V8 and will be subject to change without any notice.

https://node.green/ is a website where you can easily look up the shipping features of nodejs

New features will be regularly updated on V8. In other words, in progress features will gradually be introduced into nodejs, even at unknown intervals.

You can list all in progress features available on each Node.js release through --v8-options . Note that these are incomplete and may damage V8 features, so take risks when using them:

The functions written in the docs can also be marked as stable, which is an important factor to consider in using them.

High stability level:

The level of stability is still being tested:

Global Object (Global Object):

The Global Object is available in all modules

If you have been exposed to javascript, you may know them as window objects

Simple example like when we use Global Object: setTimeout (callback, delay [, … args])

The program will delay 2000ms before executing the command.

Another example of: setInterval (callback, delay [, … args])

setInterval will repeat the function callback after every ms delay , it will repeat indefinitely unless we leave it to a stop condition.

If the delay value is greater than 2147483647 or less than 1 , the delay will be set to 1. If we pass a non-integer value (50/3 = 16,66666666), the value will be returned to integer (16).

If the callback is not a function, the TypeError error will be thrown

The following code will print the console every 2 seconds until we force it to stop (Ctrl + C), to be able to set a stop condition for it we can use another Global Object that is clearInterval

The 2 Global Objects that are quite important and familiar are __dirname (similar to path.dirname() ) and __filename

Source: Udemy Course – Nodejs For Absolute Beginer – Yogesh Patel

Chia sẻ bài viết ngay

Nguồn bài viết : Viblo