Nodejs global variables and nodejs global variables

Source: Internet
Author: User

Nodejs global variables and nodejs global variables

1. global

Similar to the window in the client javascript Runtime Environment

Module1.js:

Module. exports = {}; // The global variable global. varA = "abc ";

The global object can be omitted in actual use. It is the default root scope, which is equivalent to the window object in the web environment.

The global object has several useful attributes:

Console. log (_ dirname); // The current path console. log (_ filename); // path of the currently executed js file // global. process gets the current Process instance

2. process

Obtains information about the current Node process. It is generally used to obtain information such as environment variables.

Process. on ('exit ', function (code) {// the following code will never execute setTimeout (function () {console. log ("this code will not be executed") ;}, 0); console. log ('exit code: ', code) ;}); console. log ("program execution ended ");

 

3. console

Input and Output

Main. js:

Var c = require ("./calculator"); console. log (global. varA); // use the global object to access the "global" variable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.