SlideShare a Scribd company logo
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

What's hot

How to build a tool for operating Flink on Kubernetes
How to build a tool for operating Flink on KubernetesHow to build a tool for operating Flink on Kubernetes
How to build a tool for operating Flink on Kubernetes
AndreaMedeghini
 
JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...
JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...
JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...
Jorge Hidalgo
 
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
Codemotion
 
Iterative Development with Swagger on the JDK
Iterative Development with Swagger on the JDKIterative Development with Swagger on the JDK
Iterative Development with Swagger on the JDK
Swagger API
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPL
Mario-Leander Reimer
 
Apigility – Lightning Fast API Development - OSSCamp 2014
Apigility – Lightning Fast API Development - OSSCamp 2014 Apigility – Lightning Fast API Development - OSSCamp 2014
Apigility – Lightning Fast API Development - OSSCamp 2014
OSSCube
 
iOS Development Gems in AppCode
iOS Development Gems in AppCodeiOS Development Gems in AppCode
iOS Development Gems in AppCode
Alexey Ushakov
 
EEF : Sexy Properties, Wizards and Views - EclipseCon 11
EEF : Sexy Properties, Wizards and Views - EclipseCon 11EEF : Sexy Properties, Wizards and Views - EclipseCon 11
EEF : Sexy Properties, Wizards and Views - EclipseCon 11Chauvin Mariot
 
IP Network Stack in Ada 2012 and the Ravenscar Profile
IP Network Stack in Ada 2012 and the Ravenscar ProfileIP Network Stack in Ada 2012 and the Ravenscar Profile
IP Network Stack in Ada 2012 and the Ravenscar Profile
Stephane Carrez
 
React nativebeginner1
React nativebeginner1React nativebeginner1
React nativebeginner1
Oswald Campesato
 
Going Native With The OSGi Service Layer - Sascha Zelzer
Going Native With The OSGi Service Layer - Sascha ZelzerGoing Native With The OSGi Service Layer - Sascha Zelzer
Going Native With The OSGi Service Layer - Sascha Zelzer
mfrancis
 
Automating stateful applications with kubernetes operators - Openstack Summit...
Automating stateful applications with kubernetes operators - Openstack Summit...Automating stateful applications with kubernetes operators - Openstack Summit...
Automating stateful applications with kubernetes operators - Openstack Summit...
Jorge Morales
 
How to help your editor love your vue component library
How to help your editor love your vue component libraryHow to help your editor love your vue component library
How to help your editor love your vue component library
Piotr Tomiak
 
API Description Languages: Which Is The Right One For Me?
 API Description Languages: Which Is The Right One For Me?  API Description Languages: Which Is The Right One For Me?
API Description Languages: Which Is The Right One For Me?
ProgrammableWeb
 
C# 6
C# 6C# 6
Introduction to react native
Introduction to react nativeIntroduction to react native
Introduction to react native
Dani Akash
 
Developing a mobile cross-platform library
Developing a mobile cross-platform libraryDeveloping a mobile cross-platform library
Developing a mobile cross-platform library
Kostis Dadamis
 
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
CodelyTV
 

What's hot (18)

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

Similar to N-API NodeSummit-2017

Eclipse Che - A Revolutionary IDE for Distributed & Mainframe Development
Eclipse Che - A Revolutionary IDE for Distributed & Mainframe DevelopmentEclipse Che - A Revolutionary IDE for Distributed & Mainframe Development
Eclipse Che - A Revolutionary IDE for Distributed & Mainframe Development
DevOps.com
 
Building production-quality apps with Node.js
Building production-quality apps with Node.jsBuilding production-quality apps with Node.js
Building production-quality apps with Node.js
mattpardee
 
ASP.NET Core: The best of the new bits
ASP.NET Core: The best of the new bitsASP.NET Core: The best of the new bits
ASP.NET Core: The best of the new bits
Ken Cenerelli
 
DEV117 - Unleash the Power of the AppDev Pack and Node.js in Domino
DEV117 - Unleash the Power of the AppDev Pack and Node.js in DominoDEV117 - Unleash the Power of the AppDev Pack and Node.js in Domino
DEV117 - Unleash the Power of the AppDev Pack and Node.js in Domino
Heiko Voigt
 
Developer joy for distributed teams with CodeReady Workspaces | DevNation Tec...
Developer joy for distributed teams with CodeReady Workspaces | DevNation Tec...Developer joy for distributed teams with CodeReady Workspaces | DevNation Tec...
Developer joy for distributed teams with CodeReady Workspaces | DevNation Tec...
Red Hat Developers
 
Application Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless WorldApplication Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless World
Amazon Web Services
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
Khaled Mosharraf
 
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015
Microsoft
 
Net core
Net coreNet core
Net core
Damir Dobric
 
Data Engineer's Lunch #46: Node.js and API calls
Data Engineer's Lunch #46: Node.js and API callsData Engineer's Lunch #46: Node.js and API calls
Data Engineer's Lunch #46: Node.js and API calls
Anant Corporation
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIsNLJUG
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
Peter Hendriks
 
From monolith web app to micro-frontends
From monolith web app to micro-frontendsFrom monolith web app to micro-frontends
From monolith web app to micro-frontends
Rustam Aliyev
 
Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...
Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...
Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...
OdessaJS Conf
 
Nodejs overview
Nodejs overviewNodejs overview
Nodejs overview
Nicola Del Gobbo
 
apidays LIVE Paris 2021 - APIGEE, different ways for integrating with CI/CD p...
apidays LIVE Paris 2021 - APIGEE, different ways for integrating with CI/CD p...apidays LIVE Paris 2021 - APIGEE, different ways for integrating with CI/CD p...
apidays LIVE Paris 2021 - APIGEE, different ways for integrating with CI/CD p...
apidays
 
Content Strategy and Developer Engagement for DevPortals
Content Strategy and Developer Engagement for DevPortalsContent Strategy and Developer Engagement for DevPortals
Content Strategy and Developer Engagement for DevPortals
Axway
 
Node.js an Exectutive View
Node.js an Exectutive ViewNode.js an Exectutive View
Node.js an Exectutive View
Manuel Eusebio de Paz Carmona
 

Similar to N-API NodeSummit-2017 (20)

Eclipse Che - A Revolutionary IDE for Distributed & Mainframe Development
Eclipse Che - A Revolutionary IDE for Distributed & Mainframe DevelopmentEclipse Che - A Revolutionary IDE for Distributed & Mainframe Development
Eclipse Che - A Revolutionary IDE for Distributed & Mainframe Development
 
Building production-quality apps with Node.js
Building production-quality apps with Node.jsBuilding production-quality apps with Node.js
Building production-quality apps with Node.js
 
ASP.NET Core: The best of the new bits
ASP.NET Core: The best of the new bitsASP.NET Core: The best of the new bits
ASP.NET Core: The best of the new bits
 
DEV117 - Unleash the Power of the AppDev Pack and Node.js in Domino
DEV117 - Unleash the Power of the AppDev Pack and Node.js in DominoDEV117 - Unleash the Power of the AppDev Pack and Node.js in Domino
DEV117 - Unleash the Power of the AppDev Pack and Node.js in Domino
 
Developer joy for distributed teams with CodeReady Workspaces | DevNation Tec...
Developer joy for distributed teams with CodeReady Workspaces | DevNation Tec...Developer joy for distributed teams with CodeReady Workspaces | DevNation Tec...
Developer joy for distributed teams with CodeReady Workspaces | DevNation Tec...
 
Application Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless WorldApplication Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless World
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
 
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
 
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
 
Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015
 
Net core
Net coreNet core
Net core
 
Data Engineer's Lunch #46: Node.js and API calls
Data Engineer's Lunch #46: Node.js and API callsData Engineer's Lunch #46: Node.js and API calls
Data Engineer's Lunch #46: Node.js and API calls
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
 
From monolith web app to micro-frontends
From monolith web app to micro-frontendsFrom monolith web app to micro-frontends
From monolith web app to micro-frontends
 
Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...
Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...
Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...
 
Nodejs overview
Nodejs overviewNodejs overview
Nodejs overview
 
apidays LIVE Paris 2021 - APIGEE, different ways for integrating with CI/CD p...
apidays LIVE Paris 2021 - APIGEE, different ways for integrating with CI/CD p...apidays LIVE Paris 2021 - APIGEE, different ways for integrating with CI/CD p...
apidays LIVE Paris 2021 - APIGEE, different ways for integrating with CI/CD p...
 
Content Strategy and Developer Engagement for DevPortals
Content Strategy and Developer Engagement for DevPortalsContent Strategy and Developer Engagement for DevPortals
Content Strategy and Developer Engagement for DevPortals
 
Node.js an Exectutive View
Node.js an Exectutive ViewNode.js an Exectutive View
Node.js an Exectutive View
 

Recently uploaded

AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 

Recently uploaded (20)

AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 

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: Arunesh.Chandra@Microsoft.com 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: michael_dawson@ca.ibm.com 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.