Security News
Python Overtakes JavaScript as Top Programming Language on GitHub
Python becomes GitHub's top language in 2024, driven by AI and data science projects, while AI-powered security tools are gaining adoption.
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.
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);
node-addon-api is an alternative to 'nan' that provides a C++ wrapper classes which simplify the use of the Node.js Addon API. It aims to provide a more stable API across Node.js versions and is recommended by the Node.js team as the primary interface for writing native addons.
ffi-napi is a Node.js addon for loading and calling dynamic libraries using pure JavaScript. It is similar to 'nan' in that it allows interaction with native code, but it focuses on foreign function interfaces rather than providing abstractions for writing native modules.
ref-napi is a package that provides a way to create, access, and manipulate binary data in Buffer instances in Node.js. It is similar to 'nan' in that it deals with native memory management, but it is more focused on buffer manipulation rather than abstracting Node.js and V8 APIs.
1.6.2 Feb 6 2015
FAQs
Native Abstractions for Node.js: C++ header for Node 0.8 -> 23 compatibility
The npm package nan receives a total of 18,230,267 weekly downloads. As such, nan popularity was classified as popular.
We found that nan demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
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.
Security News
Python becomes GitHub's top language in 2024, driven by AI and data science projects, while AI-powered security tools are gaining adoption.
Security News
Dutch National Police and FBI dismantle Redline and Meta infostealer malware-as-a-service operations in Operation Magnus, seizing servers and source code.
Research
Security News
Socket is tracking a new trend where malicious actors are now exploiting the popularity of LLM research to spread malware through seemingly useful open source packages.