Socket
Socket
Sign inDemoInstall

nan

Package Overview
Dependencies
0
Maintainers
2
Versions
87
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nan

Native Abstractions for Node.js: C++ header for Node 0.8->0.12 compatibility


Version published
Weekly downloads
17M
increased by0.41%
Maintainers
2
Install size
112 kB
Created
Weekly downloads
 

Package description

What is nan?

The 'nan' package stands for 'Native Abstractions for Node.js'. It is a header file that wraps Node.js and V8 APIs, providing a set of utilities for native module developers to create and maintain native addons across Node.js versions.

What are nan's main functionalities?

Simple Asynchronous Operations

This feature allows developers to perform asynchronous operations in their native addons. The code sample demonstrates how to create an asynchronous worker using 'NanAsyncWorker' and queue it with 'NanAsyncQueueWorker'.

const { NanAsyncWorker, NanAsyncQueueWorker } = require('nan');

class MyWorker extends NanAsyncWorker {
  constructor(callback) {
    super(callback);
  }
  Execute() {
    // perform heavy task
  }
  HandleOKCallback() {
    this->callback().Call(0, nullptr);
  }
}

NanAsyncQueueWorker(new MyWorker(new NanCallback(callback)));

Persistent References

This feature provides a way to create persistent references to V8 objects that won't be garbage collected until explicitly cleared. The code sample shows how to create, reset, check, and clear a persistent reference.

const { NanPersistent } = require('nan');

let persistent = new NanPersistent<v8::Object>();

persistent.Reset(obj); // obj is a V8 object
persistent.IsEmpty(); // checks if the persistent handle is empty
persistent.Clear(); // clears the persistent handle

Callbacks

This feature allows native module developers to store and invoke callbacks. The code sample illustrates how to create a 'NanCallback' from a V8 function and invoke it with no arguments.

const { NanCallback } = require('nan');

let callback = new NanCallback(info[0].As<v8::Function>());
callback.Call(0, nullptr);

Other packages similar to nan

Changelog

Source

1.7.0 Feb 28 2015

  • Feature: Made NanCallback::Call accept optional target 8d54da7
    • Feature: Support atom-shell 0.21 0b7f1bb

FAQs

Last updated on 28 Feb 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc