Node basics-Global

Source: Internet
Author: User

Global Object:

  • Global: Always use VaR to define variables to avoid introducing global variables;
  • Process: The content of all global execution contexts is in the Process object;

Module System:Three global variables

  • Require (): If the module is not in node_modules, the relative path must be used for import;
  • Exports: Some attributes can be defined on this object. APIs exposed using this object as a module;
  • Module: exports is module. Exports. you can completely overwrite exports and change it to an exposed API;

Listener event:Eventemitter; comparison window. addeventlisten;

VaR eventemitter = require ('events '). eventemitter; // obtain the listener method corresponding to the import module; var A = new eventemitter; // create an object based on this method;. on ('event', function () {});/. once ('event', function () {}); // listens to related events on this object

 

Node basics-Global

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.