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
Node-ChakraCore Project
Time-Travel Debugging
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, 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!
N-API 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
The response so far …
Is it the new NaN ?
• N-API has more complete isolation from V8
• Compile once/run multiple versions
• Both C and C++ usage supported
• N-API expected to replace NaN usage
Ported Modules
• Node-Sass
• Canvas
• SQLlite
• LevelDown
• Nanomsg
• IoTivity
N-API Demo
----------------------------------------------------------------------------------------------------
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 }
napi_value Init(napi_env env, napi_value exports) {
napi_value new_exports;
napi_status status =
napi_create_function(env, "", NAPI_AUTO_LENGTH, RunCallback, nullptr, &new_exports);
assert(status == napi_ok);
return new_exports;
}
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, nullptr, nullptr);
napi_value cb = args[0];
napi_value argv[1];
status = napi_create_string_utf8(env, "hello world", NAPI_AUTO_LENGTH, 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
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::Env env = info.Env();
Napi::Function cb = info[0].As<Napi::Function>();
cb.MakeCallback(env.Global(), {
Napi::String::New(env, "hello world")
});
}
https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/3_callbacks/node-addon-api
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>
Napi::Object Init(Napi::Env env, Napi::Object exports) {
return Napi::Function::New(env, 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
Calling all native module maintainers
and Node.js enthusiasts
• Help wanted to port popular native modules
• Try out one of the ported modules and provide feedback
• Improve the documentation
• Improve test coverage
• Join the N-API Working Group
https://github.com/nodejs/abi-stable-node
Useful Links
• Conversion tool for migrating existing NaN modules to N-API
https://github.com/nodejs/node-addon-api/blob/master/tools/conversion.js
• Yeoman generator for building N-API module from scratch
https://github.com/digitalinfinity/generator-napi-module (C++ Wrapper)
• Guidance for publishing N-API versions of your modules
https://nodejs.org/en/docs/guides/publishing-napi-modules/
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

Intro to Eclipse Che, by Tyler Jewell
Intro to Eclipse Che, by Tyler JewellIntro to Eclipse Che, by Tyler Jewell
Intro to Eclipse Che, by Tyler Jewell
jwi11iams
 
Introduction to Eclipse Che / EclipseCon 2014
Introduction to Eclipse Che / EclipseCon 2014Introduction to Eclipse Che / EclipseCon 2014
Introduction to Eclipse Che / EclipseCon 2014
Florent BENOIT
 
Kubernetes Operators: Rob Szumski
Kubernetes Operators: Rob SzumskiKubernetes Operators: Rob Szumski
Kubernetes Operators: Rob Szumski
Redis Labs
 
Sailing into 2018 with Kubernetes and Istio
Sailing into 2018 with Kubernetes and IstioSailing into 2018 with Kubernetes and Istio
Sailing into 2018 with Kubernetes and Istio
Fernand Galiana
 
An Introduction to Eclipse Che - Next-Gen Eclipse Java IDE
An Introduction to Eclipse Che - Next-Gen Eclipse Java IDEAn Introduction to Eclipse Che - Next-Gen Eclipse Java IDE
An Introduction to Eclipse Che - Next-Gen Eclipse Java IDE
KubeAcademy
 
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
Chauvin Mariot
 
Formacion en movilidad: Conceptos de desarrollo en iOS (I)
Formacion en movilidad: Conceptos de desarrollo en iOS (I) Formacion en movilidad: Conceptos de desarrollo en iOS (I)
Formacion en movilidad: Conceptos de desarrollo en iOS (I)
Mobivery
 
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
 
Writer APIs in Java faster with Swagger Inflector
Writer APIs in Java faster with Swagger InflectorWriter APIs in Java faster with Swagger Inflector
Writer APIs in Java faster with Swagger Inflector
Tony Tam
 
[DEPRECATED]Gradle the android
[DEPRECATED]Gradle the android[DEPRECATED]Gradle the android
[DEPRECATED]Gradle the android
Jun Liu
 
kubernetes operators
kubernetes operatorskubernetes operators
kubernetes operators
Juraj Hantak
 
WJAX 2013: Java8-Tooling in Eclipse
WJAX 2013: Java8-Tooling in EclipseWJAX 2013: Java8-Tooling in Eclipse
WJAX 2013: Java8-Tooling in Eclipse
martinlippert
 
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
 
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
 
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
 
Spring Tooling: What's new and what's coming
Spring Tooling: What's new and what's comingSpring Tooling: What's new and what's coming
Spring Tooling: What's new and what's coming
martinlippert
 
Ionic 2 - Introduction
Ionic 2 - IntroductionIonic 2 - Introduction
Ionic 2 - Introduction
Stiliyan Kanchev
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDK
Sebastian Mauer
 
Openshift operator insight
Openshift operator insightOpenshift operator insight
Openshift operator insight
Ryan ZhangCheng
 
ContainerDayVietnam2016: Become a Cloud-native Developer
ContainerDayVietnam2016: Become a Cloud-native DeveloperContainerDayVietnam2016: Become a Cloud-native Developer
ContainerDayVietnam2016: Become a Cloud-native Developer
Docker-Hanoi
 

What's hot (20)

Intro to Eclipse Che, by Tyler Jewell
Intro to Eclipse Che, by Tyler JewellIntro to Eclipse Che, by Tyler Jewell
Intro to Eclipse Che, by Tyler Jewell
 
Introduction to Eclipse Che / EclipseCon 2014
Introduction to Eclipse Che / EclipseCon 2014Introduction to Eclipse Che / EclipseCon 2014
Introduction to Eclipse Che / EclipseCon 2014
 
Kubernetes Operators: Rob Szumski
Kubernetes Operators: Rob SzumskiKubernetes Operators: Rob Szumski
Kubernetes Operators: Rob Szumski
 
Sailing into 2018 with Kubernetes and Istio
Sailing into 2018 with Kubernetes and IstioSailing into 2018 with Kubernetes and Istio
Sailing into 2018 with Kubernetes and Istio
 
An Introduction to Eclipse Che - Next-Gen Eclipse Java IDE
An Introduction to Eclipse Che - Next-Gen Eclipse Java IDEAn Introduction to Eclipse Che - Next-Gen Eclipse Java IDE
An Introduction to Eclipse Che - Next-Gen Eclipse Java IDE
 
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
 
Formacion en movilidad: Conceptos de desarrollo en iOS (I)
Formacion en movilidad: Conceptos de desarrollo en iOS (I) Formacion en movilidad: Conceptos de desarrollo en iOS (I)
Formacion en movilidad: Conceptos de desarrollo en iOS (I)
 
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
 
Writer APIs in Java faster with Swagger Inflector
Writer APIs in Java faster with Swagger InflectorWriter APIs in Java faster with Swagger Inflector
Writer APIs in Java faster with Swagger Inflector
 
[DEPRECATED]Gradle the android
[DEPRECATED]Gradle the android[DEPRECATED]Gradle the android
[DEPRECATED]Gradle the android
 
kubernetes operators
kubernetes operatorskubernetes operators
kubernetes operators
 
WJAX 2013: Java8-Tooling in Eclipse
WJAX 2013: Java8-Tooling in EclipseWJAX 2013: Java8-Tooling in Eclipse
WJAX 2013: Java8-Tooling in Eclipse
 
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...
 
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
 
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
 
Spring Tooling: What's new and what's coming
Spring Tooling: What's new and what's comingSpring Tooling: What's new and what's coming
Spring Tooling: What's new and what's coming
 
Ionic 2 - Introduction
Ionic 2 - IntroductionIonic 2 - Introduction
Ionic 2 - Introduction
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDK
 
Openshift operator insight
Openshift operator insightOpenshift operator insight
Openshift operator insight
 
ContainerDayVietnam2016: Become a Cloud-native Developer
ContainerDayVietnam2016: Become a Cloud-native DeveloperContainerDayVietnam2016: Become a Cloud-native Developer
ContainerDayVietnam2016: Become a Cloud-native Developer
 

Similar to N api - node interactive 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
 
Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015
Microsoft
 
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
 
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
 
When to use Serverless? When to use Kubernetes?
When to use Serverless? When to use Kubernetes?When to use Serverless? When to use Kubernetes?
When to use Serverless? When to use Kubernetes?
Niklas Heidloff
 
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
 
Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...
Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...
Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...
mfrancis
 
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
Amazon Web Services
 
Continuous API Strategies for Integrated Platforms
 Continuous API Strategies for Integrated Platforms Continuous API Strategies for Integrated Platforms
Continuous API Strategies for Integrated Platforms
Bill Doerrfeld
 
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
 
DevOps demystified
DevOps demystifiedDevOps demystified
DevOps demystified
Xebia IT Architects
 
Nodejs overview
Nodejs overviewNodejs overview
Nodejs overview
Nicola Del Gobbo
 
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
 
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
 
Building a REST API Microservice for the DevNet API Scavenger Hunt
Building a REST API Microservice for the DevNet API Scavenger HuntBuilding a REST API Microservice for the DevNet API Scavenger Hunt
Building a REST API Microservice for the DevNet API Scavenger Hunt
Ashley Roach
 
PaaS Anywhere - Deploying an OpenShift PaaS into your Cloud Provider of Choice
PaaS Anywhere - Deploying an OpenShift PaaS into your Cloud Provider of ChoicePaaS Anywhere - Deploying an OpenShift PaaS into your Cloud Provider of Choice
PaaS Anywhere - Deploying an OpenShift PaaS into your Cloud Provider of Choice
Isaac Christoffersen
 
DevNation
DevNation DevNation
DevNation
jwi11iams
 
Priming Your Teams For Microservice Deployment to the Cloud
Priming Your Teams For Microservice Deployment to the CloudPriming Your Teams For Microservice Deployment to the Cloud
Priming Your Teams For Microservice Deployment to the Cloud
Matt Callanan
 

Similar to N api - node interactive 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
 
Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015
 
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
 
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
 
When to use Serverless? When to use Kubernetes?
When to use Serverless? When to use Kubernetes?When to use Serverless? When to use Kubernetes?
When to use Serverless? When to use Kubernetes?
 
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
 
Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...
Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...
Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...
 
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
 
Continuous API Strategies for Integrated Platforms
 Continuous API Strategies for Integrated Platforms Continuous API Strategies for Integrated Platforms
Continuous API Strategies for Integrated Platforms
 
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)
 
DevOps demystified
DevOps demystifiedDevOps demystified
DevOps demystified
 
Nodejs overview
Nodejs overviewNodejs overview
Nodejs overview
 
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
 
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)
 
Building a REST API Microservice for the DevNet API Scavenger Hunt
Building a REST API Microservice for the DevNet API Scavenger HuntBuilding a REST API Microservice for the DevNet API Scavenger Hunt
Building a REST API Microservice for the DevNet API Scavenger Hunt
 
PaaS Anywhere - Deploying an OpenShift PaaS into your Cloud Provider of Choice
PaaS Anywhere - Deploying an OpenShift PaaS into your Cloud Provider of ChoicePaaS Anywhere - Deploying an OpenShift PaaS into your Cloud Provider of Choice
PaaS Anywhere - Deploying an OpenShift PaaS into your Cloud Provider of Choice
 
DevNation
DevNation DevNation
DevNation
 
Priming Your Teams For Microservice Deployment to the Cloud
Priming Your Teams For Microservice Deployment to the CloudPriming Your Teams For Microservice Deployment to the Cloud
Priming Your Teams For Microservice Deployment to the Cloud
 

More from Michael Dawson

Index 2018 talk to your code
Index 2018   talk to your codeIndex 2018   talk to your code
Index 2018 talk to your code
Michael Dawson
 
Index 2018 node.js what's next
Index 2018   node.js what's nextIndex 2018   node.js what's next
Index 2018 node.js what's next
Michael Dawson
 
Accelerate your digital transformation
Accelerate your digital transformationAccelerate your digital transformation
Accelerate your digital transformation
Michael Dawson
 
Ask us anything v9
Ask us anything v9Ask us anything v9
Ask us anything v9
Michael Dawson
 
Node.js Community Benchmarking WG update
Node.js Community  Benchmarking WG updateNode.js Community  Benchmarking WG update
Node.js Community Benchmarking WG update
Michael Dawson
 
Cascon intro
Cascon introCascon intro
Cascon intro
Michael Dawson
 
A294 fips support in node
A294  fips support in nodeA294  fips support in node
A294 fips support in node
Michael Dawson
 
A295 nodejs-knowledge-accelerator
A295   nodejs-knowledge-acceleratorA295   nodejs-knowledge-accelerator
A295 nodejs-knowledge-accelerator
Michael Dawson
 
A301 ctu madrid2016-monitoring
A301 ctu madrid2016-monitoringA301 ctu madrid2016-monitoring
A301 ctu madrid2016-monitoring
Michael Dawson
 
Post mortem talk - Node Interactive EU
Post mortem talk - Node Interactive EUPost mortem talk - Node Interactive EU
Post mortem talk - Node Interactive EU
Michael Dawson
 
Update from-build-workgroup
Update from-build-workgroupUpdate from-build-workgroup
Update from-build-workgroup
Michael Dawson
 
Node fips
Node fipsNode fips
Node fips
Michael Dawson
 
Micro app-framework - NodeLive Boston
Micro app-framework - NodeLive BostonMicro app-framework - NodeLive Boston
Micro app-framework - NodeLive Boston
Michael Dawson
 
Node liveboston welcome
Node liveboston welcomeNode liveboston welcome
Node liveboston welcome
Michael Dawson
 
Micro app-framework
Micro app-frameworkMicro app-framework
Micro app-framework
Michael Dawson
 
Node home automation with Node.js and MQTT
Node home automation with Node.js and MQTTNode home automation with Node.js and MQTT
Node home automation with Node.js and MQTT
Michael Dawson
 
Java one 2015 - v1
Java one   2015 - v1Java one   2015 - v1
Java one 2015 - v1
Michael Dawson
 

More from Michael Dawson (17)

Index 2018 talk to your code
Index 2018   talk to your codeIndex 2018   talk to your code
Index 2018 talk to your code
 
Index 2018 node.js what's next
Index 2018   node.js what's nextIndex 2018   node.js what's next
Index 2018 node.js what's next
 
Accelerate your digital transformation
Accelerate your digital transformationAccelerate your digital transformation
Accelerate your digital transformation
 
Ask us anything v9
Ask us anything v9Ask us anything v9
Ask us anything v9
 
Node.js Community Benchmarking WG update
Node.js Community  Benchmarking WG updateNode.js Community  Benchmarking WG update
Node.js Community Benchmarking WG update
 
Cascon intro
Cascon introCascon intro
Cascon intro
 
A294 fips support in node
A294  fips support in nodeA294  fips support in node
A294 fips support in node
 
A295 nodejs-knowledge-accelerator
A295   nodejs-knowledge-acceleratorA295   nodejs-knowledge-accelerator
A295 nodejs-knowledge-accelerator
 
A301 ctu madrid2016-monitoring
A301 ctu madrid2016-monitoringA301 ctu madrid2016-monitoring
A301 ctu madrid2016-monitoring
 
Post mortem talk - Node Interactive EU
Post mortem talk - Node Interactive EUPost mortem talk - Node Interactive EU
Post mortem talk - Node Interactive EU
 
Update from-build-workgroup
Update from-build-workgroupUpdate from-build-workgroup
Update from-build-workgroup
 
Node fips
Node fipsNode fips
Node fips
 
Micro app-framework - NodeLive Boston
Micro app-framework - NodeLive BostonMicro app-framework - NodeLive Boston
Micro app-framework - NodeLive Boston
 
Node liveboston welcome
Node liveboston welcomeNode liveboston welcome
Node liveboston welcome
 
Micro app-framework
Micro app-frameworkMicro app-framework
Micro app-framework
 
Node home automation with Node.js and MQTT
Node home automation with Node.js and MQTTNode home automation with Node.js and MQTT
Node home automation with Node.js and MQTT
 
Java one 2015 - v1
Java one   2015 - v1Java one   2015 - v1
Java one 2015 - v1
 

Recently uploaded

Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 

Recently uploaded (20)

Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 

N api - node interactive 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 Node-ChakraCore Project Time-Travel Debugging 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, 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!
  • 6. N-API available as Experimental in Node.js 8!
  • 7. 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
  • 8. The response so far …
  • 9. Is it the new NaN ? • N-API has more complete isolation from V8 • Compile once/run multiple versions • Both C and C++ usage supported • N-API expected to replace NaN usage
  • 10. Ported Modules • Node-Sass • Canvas • SQLlite • LevelDown • Nanomsg • IoTivity
  • 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 } napi_value Init(napi_env env, napi_value exports) { napi_value new_exports; napi_status status = napi_create_function(env, "", NAPI_AUTO_LENGTH, RunCallback, nullptr, &new_exports); assert(status == napi_ok); return new_exports; } 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, nullptr, nullptr); napi_value cb = args[0]; napi_value argv[1]; status = napi_create_string_utf8(env, "hello world", NAPI_AUTO_LENGTH, 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
  • 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::Env env = info.Env(); Napi::Function cb = info[0].As<Napi::Function>(); cb.MakeCallback(env.Global(), { Napi::String::New(env, "hello world") }); } https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/3_callbacks/node-addon-api 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> Napi::Object Init(Napi::Env env, Napi::Object exports) { return Napi::Function::New(env, 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. Calling all native module maintainers and Node.js enthusiasts • Help wanted to port popular native modules • Try out one of the ported modules and provide feedback • Improve the documentation • Improve test coverage • Join the N-API Working Group https://github.com/nodejs/abi-stable-node
  • 19. Useful Links • Conversion tool for migrating existing NaN modules to N-API https://github.com/nodejs/node-addon-api/blob/master/tools/conversion.js • Yeoman generator for building N-API module from scratch https://github.com/digitalinfinity/generator-napi-module (C++ Wrapper) • Guidance for publishing N-API versions of your modules https://nodejs.org/en/docs/guides/publishing-napi-modules/
  • 20. 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.

Editor's Notes

  1. Welcome to this talk on N-API! How many of you have heard of N-API ? Well this is a joint talk, I’m going to start of and give you an overview of what and why and show you a demo Michael will dive deeper and talk about the nuts and bolts about the API So let’s get started!
  2. Today due to the lack of ABI stability in Node.js - the native node module ecosystem suffers from breakage for every new Node release. According to some estimates approc 30% of the module ecosystem gets impacted by this. Module maintainers have to invest time to update their support for new versions and module consumers don’t upgrade their node versions due to these compatibility issues.
  3. N-API enabled modules will improve experience for module consumers – it will reduce friction in upgrading to new versions and also reduce maintaince cost for the module maintainers
  4. The community certainly feels really good about this new feature in Node.js 8
  5. Well you can say how is it different from NaN ?
  6. While designing and implementing N-API – we have converted these popular native modules to N-API
  7. Common error handling patterns   - returns status – if 0 all ok   - if non-zero check status and/or pending exception   Result passed back as in/out parameter
  8. napi_get_cb_info all but env and info are optional