N-API: Next Generation Node
API for native modules
Arunesh Chandra, Microsoft
Michael Dawson, IBM
Arunesh Chandra, Microsoft
Senior Program Manager @ Microsoft
Developer Tools and Services for Node.js
Time-Travel Debugging
Node.js Community
Node-ChakraCore, N-API WG
Contact me:
Arunesh.Chandra@Microsoft.com
Twitter: @AruneshC
Github: @aruneshchandra
Michael Dawson, IBM
Senior Software Developer @ IBM
IBM Node.js community lead/IBM Runtime Technologies
Node.js collaborator, CTC and TSC member
Active in LTS, build, benchmarking, api and post-mortem working groups
Contact me:
michael_dawson@ca.ibm.com
Twitter: @mhdawson1
Github: @mhdawson
Linkedin: https://www.linkedin.com/in/michael-dawson-6051282
Contributors
What is N-API ?
N-API is a stable Node API layer for native modules, that
provides ABI compatibility guarantees across different
Node versions & flavors.
N-API enables native modules to just work across different versions and
flavors of Node.js without recompilations!
Available as Experimental in Node.js 8
Why do I care about N-API ?
Reduces maintenance cost for Native module
maintainers
Reduces friction from upgrading
to newer Node.js versions in
production deployments
What are people saying about it …
Is it the new NaN ?
• N-API has more complete isolation from V8
• Compile once/run multiple versions and flavors of Node
• Both C and C++ usage supported
• N-API expected to replace NaN usage
Ported Modules
• Node-Sass
• Canvas
• SQLlite
• LevelDown
• Nanomsg
• IoTivity
N-API Coverage
Data based on Top 30 depended on native modules
195 Total V8 APIs used in 30 modules
140/195 N-API equivalent exists
83/195 Exercised by 5 ported modules
v8:Isolate APIs
no N-API equivalence planned
N-API Demo
----------------------------------------------------------------------------------------------------
github: https://github.com/boingoing/napi_demo
YouTube: https://www.youtube.com/watch?v=nmXhJ88nZsk
API Shape
napi_status napi_create_array(napi_env env, napi_value* result);
napi_status napi_get_last_error_info(napi_env e, const napi_extended_error_info** result);
napi_status napi_is_exception_pending(napi_env e, bool* result);
napi_status napi_get_and_clear_last_exception(napi_env e, napi_value* result);
napi_status napi_throw(napi_env e, napi_value error);
• Collection of C APIs available natively in Node.js 8.0
• API Docs -
https://nodejs.org/dist/latest-v8.x/docs/api/n-api.html
• ../src/node_api.h
Examples – C- API
#include <node_api.h>
napi_value RunCallback(napi_env env, const napi_callback_info info) {
...
}
#define DECLARE_NAPI_METHOD(name, func) 
{ name, 0, func, 0, 0, 0, napi_default, 0 }
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_status status;
napi_property_descriptor desc = DECLARE_NAPI_METHOD("exports", RunCallback);
status = napi_define_properties(env, module, 1, &desc);
assert(status == napi_ok);
}
NAPI_MODULE(addon, Init)
https://github.com/nodejs/abi-stable-node-addon-examples
3_callbacks
Examples – C- API
#include <node_api.h>
napi_value RunCallback(napi_env env, const napi_callback_info info) {
napi_status status;
size_t argc = 1;
napi_value args[1];
status = napi_get_cb_info(env, info, &argc, args, NULL, NULL);
napi_value cb = args[0];
napi_value argv[1];
status = napi_create_string_utf8(env, "hello world", -1, argv);
napi_value global;
status = napi_get_global(env, &global);
napi_value result;
status = napi_call_function(env, global, cb, 1, argv, &result);
return nullptr;
}
optional 'this'
optional 'data pointer'
optional length
NODE_BUILD=/home/mhdawson/newpull/io.js
export PATH=$NODE_BUILD:$NODE_BUILD/../abi-stable-node-addon-
examples/node_modules/node-gyp/bin/:$PATH
export NPM=$NODE_BUILD/deps/npm/bin/npm-cli.js
alias npm=$NPM
alias node-gyp=node-gyp.js
export npm_config_nodedir=$NODE_BUILD
export NODE_OPTIONS=--napi-modules
Example – C++ Wrapper Module
https://github.com/nodejs/node-addon-api
https://www.npmjs.com/package/node-addon-api
https://nodejs.github.io/node-addon-api/namespace_napi.html
Example – C++ Wrapper Example
NaN node-addon-api
void Init(v8::Local<v8::Object> exports,
v8::Local<v8::Object> module) {
Nan::SetMethod(module, "exports", RunCallback);
}
void RunCallback(const Napi::CallbackInfo& info) {
Napi::Function cb = info[0].As<Napi::Function>();
cb.MakeCallback(info.Env().Global(), { Napi::String::New(info.Env(),
"hello world") });
}
https://github.com/nodejs/node-addon-api/blob/master/tools/conversion.js
#include <nan.h>
void RunCallback(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
v8::Local<v8::Function> cb = info[0].As<v8::Function>();
const unsigned argc = 1;
v8::Local<v8::Value> argv[argc] = { Nan::New("hello
world").ToLocalChecked() };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), cb, argc,
argv);
}
NODE_MODULE(addon, Init)
#include <napi.h>
void Init(Napi::Env env, Napi::Object exports, Napi::Object module) {
module.DefineProperty(Napi::PropertyDescriptor::Function("exports",
RunCallback));
}
NODE_API_MODULE(addon, Init)
Backward Compatibility
• Available in 8.x
• Plan to backport to 6.x
• For 4.x
• Copy of API built into node-addon-api
module
• Do NOT get build once/run any version
• Can maintain module with single code base
Tools for getting started
• From scratch
• https://github.com/digitalinfinity/generator-napi-module (C++ Wrapper)
• Migrating from NaN
• https://github.com/nodejs/node-addon-api/blob/master/tools/conversion.js
How you can help
• Port a module
• Try out one of the ported modules
• Help improve the documentation
• Improve test coverage
• Join the N-API Working Group
Calling all native module maintainers
• Feedback is key to success
• Earlier the Better
• Helps overall community
• API additions prioritized by need
• We are reaching out
• Need leading modules to help out
• We understand it will take time
• Guidance for publishing n-api versions
• https://nodejs.org/en/docs/guides/publishing-napi-modules/
https://github.com/nodejs/abi-stable-node/milestone/5
Copyright and Trademarks
© IBM Corporation and Microsoft Corporation, 2017. All Rights Reserved
IBM, the IBM logo, ibm.com are trademarks or registered
trademarks of International Business Machines Corp.,
registered in many jurisdictions worldwide. Other product and
service names might be trademarks of IBM or other companies.
A current list of IBM trademarks is available on the Web at
“Copyright and trademark information” at
www.ibm.com/legal/copytrade.shtml
Microsoft is a trademark of Microsoft Corporation in the United States, other countries, or both.
Node.js is an official trademark of Joyent. IBM SDK for Node.js is not formally related to or endorsed by the official Joyent
Node.js open source or commercial project.
Java, JavaScript and all Java-based trademarks and logos are trademarks or registered trademarks of Oracle and/or its
affiliates.
npm is a trademark of npm, Inc.

More Related Content

PPTX
N api - node interactive 2017
PPTX
Next Generation N-API
PPTX
PPTX
Nodejs Native Add-Ons from zero to hero
PDF
Working effectively with OpenShift
PDF
Developing Great Apps with Apache Cordova
PPTX
Nativescript with angular 2
PPTX
Writer APIs in Java faster with Swagger Inflector
N api - node interactive 2017
Next Generation N-API
Nodejs Native Add-Ons from zero to hero
Working effectively with OpenShift
Developing Great Apps with Apache Cordova
Nativescript with angular 2
Writer APIs in Java faster with Swagger Inflector

What's hot (18)

PDF
How to build a tool for operating Flink on Kubernetes
PPTX
JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...
PDF
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
PPTX
Iterative Development with Swagger on the JDK
PDF
Everything-as-code. A polyglot adventure. #DevoxxPL
PDF
Apigility – Lightning Fast API Development - OSSCamp 2014
PDF
iOS Development Gems in AppCode
PDF
EEF : Sexy Properties, Wizards and Views - EclipseCon 11
PDF
IP Network Stack in Ada 2012 and the Ravenscar Profile
PPTX
React nativebeginner1
PDF
Going Native With The OSGi Service Layer - Sascha Zelzer
PDF
Automating stateful applications with kubernetes operators - Openstack Summit...
PDF
How to help your editor love your vue component library
PDF
API Description Languages: Which Is The Right One For Me?
PPTX
PDF
Introduction to react native
PPTX
Developing a mobile cross-platform library
PDF
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
How to build a tool for operating Flink on Kubernetes
JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
Iterative Development with Swagger on the JDK
Everything-as-code. A polyglot adventure. #DevoxxPL
Apigility – Lightning Fast API Development - OSSCamp 2014
iOS Development Gems in AppCode
EEF : Sexy Properties, Wizards and Views - EclipseCon 11
IP Network Stack in Ada 2012 and the Ravenscar Profile
React nativebeginner1
Going Native With The OSGi Service Layer - Sascha Zelzer
Automating stateful applications with kubernetes operators - Openstack Summit...
How to help your editor love your vue component library
API Description Languages: Which Is The Right One For Me?
Introduction to react native
Developing a mobile cross-platform library
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
Ad

Similar to N-API NodeSummit-2017 (20)

PPTX
Nodejs overview
PDF
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
PDF
PDF
Nodifying the Enterprise - Prince Soni, TO THE NEW
PPTX
Node js with steroids
PPTX
Introduction to NodeJS
PDF
Node.js an Exectutive View
PPTX
Node.js/io.js Native C++ Addons
PDF
How to Enterprise Node
PDF
InterConnect2016: WebApp Architectures with Java and Node.js
PDF
API Microservices with Node.js and Docker
PDF
Node.js for .NET Developers
PPTX
React Native new architecture Power Point
PDF
InterConnect 2017 : Programming languages in the enterprise: Which language s...
PDF
The Enterprise Case for Node.js
PDF
Server Side Apocalypse, JS
PPTX
Essentials nodejs learning kit
PPTX
Essentials nodejs learning kit
PPTX
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
PPTX
Overview of Node JS
Nodejs overview
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
Nodifying the Enterprise - Prince Soni, TO THE NEW
Node js with steroids
Introduction to NodeJS
Node.js an Exectutive View
Node.js/io.js Native C++ Addons
How to Enterprise Node
InterConnect2016: WebApp Architectures with Java and Node.js
API Microservices with Node.js and Docker
Node.js for .NET Developers
React Native new architecture Power Point
InterConnect 2017 : Programming languages in the enterprise: Which language s...
The Enterprise Case for Node.js
Server Side Apocalypse, JS
Essentials nodejs learning kit
Essentials nodejs learning kit
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Overview of Node JS
Ad

Recently uploaded (20)

PDF
4 layer Arch & Reference Arch of IoT.pdf
PPTX
Training Program for knowledge in solar cell and solar industry
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
Comparative analysis of machine learning models for fake news detection in so...
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PDF
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PDF
Five Habits of High-Impact Board Members
PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
Consumable AI The What, Why & How for Small Teams.pdf
PPTX
Build Your First AI Agent with UiPath.pptx
PDF
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PPT
Geologic Time for studying geology for geologist
PPTX
Module 1 Introduction to Web Programming .pptx
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
4 layer Arch & Reference Arch of IoT.pdf
Training Program for knowledge in solar cell and solar industry
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
Comparative analysis of machine learning models for fake news detection in so...
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
Flame analysis and combustion estimation using large language and vision assi...
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
OpenACC and Open Hackathons Monthly Highlights July 2025
Five Habits of High-Impact Board Members
UiPath Agentic Automation session 1: RPA to Agents
Consumable AI The What, Why & How for Small Teams.pdf
Build Your First AI Agent with UiPath.pptx
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
Enhancing plagiarism detection using data pre-processing and machine learning...
Geologic Time for studying geology for geologist
Module 1 Introduction to Web Programming .pptx
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
Credit Without Borders: AI and Financial Inclusion in Bangladesh

N-API NodeSummit-2017

  • 1. N-API: Next Generation Node API for native modules Arunesh Chandra, Microsoft Michael Dawson, IBM
  • 2. Arunesh Chandra, Microsoft Senior Program Manager @ Microsoft Developer Tools and Services for Node.js Time-Travel Debugging Node.js Community Node-ChakraCore, N-API WG Contact me: [email protected] Twitter: @AruneshC Github: @aruneshchandra
  • 3. Michael Dawson, IBM Senior Software Developer @ IBM IBM Node.js community lead/IBM Runtime Technologies Node.js collaborator, CTC and TSC member Active in LTS, build, benchmarking, api and post-mortem working groups Contact me: [email protected] Twitter: @mhdawson1 Github: @mhdawson Linkedin: https://www.linkedin.com/in/michael-dawson-6051282
  • 5. What is N-API ? N-API is a stable Node API layer for native modules, that provides ABI compatibility guarantees across different Node versions & flavors. N-API enables native modules to just work across different versions and flavors of Node.js without recompilations! Available as Experimental in Node.js 8
  • 6. Why do I care about N-API ? Reduces maintenance cost for Native module maintainers Reduces friction from upgrading to newer Node.js versions in production deployments
  • 7. What are people saying about it …
  • 8. Is it the new NaN ? • N-API has more complete isolation from V8 • Compile once/run multiple versions and flavors of Node • Both C and C++ usage supported • N-API expected to replace NaN usage
  • 9. Ported Modules • Node-Sass • Canvas • SQLlite • LevelDown • Nanomsg • IoTivity
  • 10. N-API Coverage Data based on Top 30 depended on native modules 195 Total V8 APIs used in 30 modules 140/195 N-API equivalent exists 83/195 Exercised by 5 ported modules v8:Isolate APIs no N-API equivalence planned
  • 12. API Shape napi_status napi_create_array(napi_env env, napi_value* result); napi_status napi_get_last_error_info(napi_env e, const napi_extended_error_info** result); napi_status napi_is_exception_pending(napi_env e, bool* result); napi_status napi_get_and_clear_last_exception(napi_env e, napi_value* result); napi_status napi_throw(napi_env e, napi_value error); • Collection of C APIs available natively in Node.js 8.0 • API Docs - https://nodejs.org/dist/latest-v8.x/docs/api/n-api.html • ../src/node_api.h
  • 13. Examples – C- API #include <node_api.h> napi_value RunCallback(napi_env env, const napi_callback_info info) { ... } #define DECLARE_NAPI_METHOD(name, func) { name, 0, func, 0, 0, 0, napi_default, 0 } void Init(napi_env env, napi_value exports, napi_value module, void* priv) { napi_status status; napi_property_descriptor desc = DECLARE_NAPI_METHOD("exports", RunCallback); status = napi_define_properties(env, module, 1, &desc); assert(status == napi_ok); } NAPI_MODULE(addon, Init) https://github.com/nodejs/abi-stable-node-addon-examples 3_callbacks
  • 14. Examples – C- API #include <node_api.h> napi_value RunCallback(napi_env env, const napi_callback_info info) { napi_status status; size_t argc = 1; napi_value args[1]; status = napi_get_cb_info(env, info, &argc, args, NULL, NULL); napi_value cb = args[0]; napi_value argv[1]; status = napi_create_string_utf8(env, "hello world", -1, argv); napi_value global; status = napi_get_global(env, &global); napi_value result; status = napi_call_function(env, global, cb, 1, argv, &result); return nullptr; } optional 'this' optional 'data pointer' optional length NODE_BUILD=/home/mhdawson/newpull/io.js export PATH=$NODE_BUILD:$NODE_BUILD/../abi-stable-node-addon- examples/node_modules/node-gyp/bin/:$PATH export NPM=$NODE_BUILD/deps/npm/bin/npm-cli.js alias npm=$NPM alias node-gyp=node-gyp.js export npm_config_nodedir=$NODE_BUILD export NODE_OPTIONS=--napi-modules
  • 15. Example – C++ Wrapper Module https://github.com/nodejs/node-addon-api https://www.npmjs.com/package/node-addon-api https://nodejs.github.io/node-addon-api/namespace_napi.html
  • 16. Example – C++ Wrapper Example NaN node-addon-api void Init(v8::Local<v8::Object> exports, v8::Local<v8::Object> module) { Nan::SetMethod(module, "exports", RunCallback); } void RunCallback(const Napi::CallbackInfo& info) { Napi::Function cb = info[0].As<Napi::Function>(); cb.MakeCallback(info.Env().Global(), { Napi::String::New(info.Env(), "hello world") }); } https://github.com/nodejs/node-addon-api/blob/master/tools/conversion.js #include <nan.h> void RunCallback(const Nan::FunctionCallbackInfo<v8::Value>& info) { v8::Local<v8::Function> cb = info[0].As<v8::Function>(); const unsigned argc = 1; v8::Local<v8::Value> argv[argc] = { Nan::New("hello world").ToLocalChecked() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), cb, argc, argv); } NODE_MODULE(addon, Init) #include <napi.h> void Init(Napi::Env env, Napi::Object exports, Napi::Object module) { module.DefineProperty(Napi::PropertyDescriptor::Function("exports", RunCallback)); } NODE_API_MODULE(addon, Init)
  • 17. Backward Compatibility • Available in 8.x • Plan to backport to 6.x • For 4.x • Copy of API built into node-addon-api module • Do NOT get build once/run any version • Can maintain module with single code base
  • 18. Tools for getting started • From scratch • https://github.com/digitalinfinity/generator-napi-module (C++ Wrapper) • Migrating from NaN • https://github.com/nodejs/node-addon-api/blob/master/tools/conversion.js
  • 19. How you can help • Port a module • Try out one of the ported modules • Help improve the documentation • Improve test coverage • Join the N-API Working Group
  • 20. Calling all native module maintainers • Feedback is key to success • Earlier the Better • Helps overall community • API additions prioritized by need • We are reaching out • Need leading modules to help out • We understand it will take time • Guidance for publishing n-api versions • https://nodejs.org/en/docs/guides/publishing-napi-modules/ https://github.com/nodejs/abi-stable-node/milestone/5
  • 21. Copyright and Trademarks © IBM Corporation and Microsoft Corporation, 2017. All Rights Reserved IBM, the IBM logo, ibm.com are trademarks or registered trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at “Copyright and trademark information” at www.ibm.com/legal/copytrade.shtml Microsoft is a trademark of Microsoft Corporation in the United States, other countries, or both. Node.js is an official trademark of Joyent. IBM SDK for Node.js is not formally related to or endorsed by the official Joyent Node.js open source or commercial project. Java, JavaScript and all Java-based trademarks and logos are trademarks or registered trademarks of Oracle and/or its affiliates. npm is a trademark of npm, Inc.