What does “this” mean in a nodejs module?

I have a simple codes like the following and execute it as a node module:

console.log(this);
module.exports = {…};

I know that global is the default context (like window in browsers), but what does the this keyword refer to?

Answers:

Answer

this (in the context of a module) is the same as exports in node.js. However you should generally use exports/module.exports instead, so that it's explicitly clear what you're modifying.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.