Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nan

Package Overview
Dependencies
Maintainers
2
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

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

  • 1.5.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15M
decreased by-8.58%
Maintainers
2
Weekly downloads
 
Created

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

FAQs

Package last updated on 23 Jan 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc