JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2520
  • Score
    100M100P100Q111513F
  • License MIT

self property in Node.js

Package Exports

  • node-self

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-self) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-self

🤙 self property in Node.js

What is this?

You can use self property in Node.js via this module.

// In Browser (Window context)
console.log(self) // Window { ... }

// In Browser (Dedicate worker context)
console.log(self) // DedicatedWorkerGlobalScope { ... }

// But, in Node.js
console.log(self) // ReferenceError: self is not defined

Why?: self property is not implement in Node.js.

Feature

You can use self property in Node.js.

  • Three lines magic
  • Super light weight
  • Safe
  • No more bugs

How to use?

Just using self. It's returns appropriate Global Object (Context Dependent)

Import index.js

There are can be self (Global Object)

  • Browser
    • Window
    • WorkerGlobalScope
      • DedicatedWorkerGlobalScope
      • SharedWorkerGlobalScope
      • ServiceWorkerGlobalScope
  • Node.js
    • global
self

// Browser
self === window // true

// Node.js
self === global // true

History

  • 2020.05.13: First Release (v1.0.0)

License

MIT