SlideShare ist ein Scribd-Unternehmen logo
1 von 55
Next Generation N-API
A hands-on workshop
N-API Team
Works at Intel
Involved with the API working
group
- Technical Steering Committee (TSC) member
- Promises
- Exception handling
- Environment propagation
- Module loading
- Wrap/Unwrap
- Thread-safe function
Gabriel Schulhof
@gabrielschulhof
gabriel.schulhof@intel.com
About Gabriel Schulhof
IBM Community Lead for Node.js
Active Node.js community member
- Technical Steering Committee (TSC) member
- Community Committee member
- n-api, build, security, benchmarking,
diagnostics,
release, user-feedback, teams and WGs.
Michael Dawson
@mhdawson1
@mhdawson
About Michael Dawson
President of inspiredware
Member of the N-API Team
- node-pre-gyp
- Prebuild
- Documentation
Jim Schlight
@inspiredware
@jschlight
About Jim Schlight
Developer at Packly
Member of the N-API Team
Nicola Del Gobbo
@NickNaso
@NickNaso
About Nicola Del Gobbo
Anna Henningsen
@addaleax
Gabriel Schulhof
@gabrielschulhof
Hitesh Kanwathirtha
@digitalinfinity
Jim Schlight
@jschlight
Michael Dawson
@mhdawson
Nicola Del Gobbo
@NickNaso
Kevin Eady
@KevinEady
Arunesh Chandra
@aruneshchandra
Taylor Wall
@boingoing
Anisha Rohra
@anisha-rohra
Kyle Farnung
@kfarnung
And many others ...
Contributors
Objectives of the
workshop
Orientation to N-API
Awareness of available tools and processes
A good start on your own projects
Workshop
schedule
1. Introduction to N-API and node-addon-api
2. Online tutorials
3. Let’s port some modules/individual projects
4. Wrap-up and assessment
What is a
native addon?
What is a native addon?
Node.js addons are dynamically-linked shared objects,
written in C or C++, that can be loaded into Node.js using
therequire() function, and used just as if they were an
ordinaryNode.js module
They are used primarily to provide an interface between
JavaScript running in Node.js and C/C++ libraries
What is a native addon?
Motivations for
N-API
Motivations for N-API
The API to implement native add-ons has been changed
across different version of Node.js
Most of the changes were on V8 API and ObjectWrap API
and other node internals
About 30% of modules depend on a native add-on.
A breakage on a native addon could become very important
e.g. node-sass
Motivations for N-API
Need an adapter to stay compatible across different
versions of Node.js
NAN - Native Abstraction for Node.js
- API compatibility
- Strongly bonded with V8 API
- You have to recompile your native add-ons when switching to a different
version
of Node.js
Motivations for N-API
End user
Maintainers
What’s
N-API
What’s N-API
◎ Abstraction of the underlying JavaScript engine
◎ Defines and exports C types and functions that are
independent from the JavaScript engine
◎ A binary-stable ABI
What’s N-API
Without N-API
Addon
Node.js: 6.12.2
V8: 5.1.281
NODE_MODULE_VERSION: 48
Node.js: 8.9.3
V8: 6.1.534
NODE_MODULE_VERSION: 57
Without N-API
● ABI break
○ At worst, mysterious segfaults
○ At best, addon fails to load
○ NODE_MODULE_VERSION mismatch
Node.js: no matter
V8/ChakraCore: no matter
NAPI_VERSION: 1
With N-API
Node.js: later
V8/ChakraCore: no matter
NAPI_VERSION: 2
With N-API
● No ABI break
○ NAPI_VERSION is cumulative
○ Addon is forwards compatible
Context
Awareness
Context Awareness
Context Awareness
Cleanup
◎ Unload DSO (one per process)
◎ Unload addon instance data
- napi_add_env_cleanup_hook() – N-API 5
- napi_set_instance_data() – experimental
◎ Clean up leftover references created with
- napi_wrap()
- napi_add_finalizer() – N-API 5
- napi_buffer_create_external()
- et. al.
GC will not free them! Need to track them and explicitly free
them!
A brief history
of N-API
A brief history of N-API
N-API and
node-addon-api
N-API and node-addon-api
◎ N-API is C whereas node-addon-api is C++
◎ node-addon-api not technically part of ABI stable API
- Helper to simplify code using C++
- All inline
- Only depends on export N-API C functions
npm install node-addon-api
About 300k downloads / week
N-API and node-addon-api
Node-addon-api
Versus NAN
Node-addon-api Versus NAN
◎ Same
- Includes a C++ wrapper
- Provides common helper functionality
- Reduces likelihood of needing to change code for new Node.js
versions
◎ Different
- Does not use V8 Types
- Not tied to a specific JavaScript engine
- Preserves compile once/run multiple versions from N-API
- Reduces even further likelihood of having to change code
What happened in
the last year
core - node-addon-api - tools
What happened in the last year (core)
◎ N-API 4
- Added thread-safe function
◎ N-API 5
- Added API to manage date object
- Finalizer callback (marked as stable)
- Optional callback in thread-safe function
- Added reference cleanup
What happened in the last year (node-addon-api)
◎ Improved documentation
◎ Added new asynchronous API
- Napi::AsyncContext
◎ Added thread-safe function
- Napi::ThreadsafeFunction
◎ Improved AsyncWorker API
- See: https://github.com/nodejs/node-addon-api/issues/231
◎ Added AsyncProgressWorker API
- Napi::AsyncProgressWorker
◎ Added API to manage date object
- Napi::Date
What happened in the last year (tools)
◎ Added support for prebuild
- A command line tool for easily making prebuilt binaries
- https://www.npmjs.com/package/prebuild#n-api-considerations
◎ Added support for cmake-js
- Build tool that uses CMake to build the native add-on instead of GYP
- https://www.npmjs.com/package/cmake-js#n-api-and-node-addon-
api
How to organize
your project
How to organize your project
◎ build folder contains the intermediary and final build products.
◎ lib folder contains the the JavaScript code that will use the native
code to export some features
◎ src folder contains the native C / C++ code
◎ test folder contains the testing code
◎ binding.gyp file that contains all settings to build the native add-on
◎ package.json npm description of your module
◎ package-lock.json used by npm to ensure deployment consistency
What’s
binding.gyp
What’s binding.gyp
By default Node.js use GYP to build
the native add-on(s).
Native add-ons are built using
node-gyp, a cross platform CLI tool
written in Node.js that contains a
fork of GYP.
GYP https://gyp.gsrc.io
node-gyp https://github.com/nodejs/node-
gyp
There are other build tools like cmake-js
Add a badge to
your project
Add a badge to your project
◎ Simply add a URL to the top of your README file
◎ Indicates the minimum N-API version your addon
supports
◎ Benefits
- Identifies your addon as supporting N-API
- Makes your addon easier to find
◎ N-API v3 is a good starting point because this is the
first version considered as stable API
Add a badge to your project
https://img.shields.io/badge/N--API-v3-green.svg
https://img.shields.io/badge/N--API-v4-green.svg
https://img.shields.io/badge/N--API-v5-green.svg
https://img.shields.io/badge/N--API-experimental-
orange.svg
Online
Tutorials
Online Tutorials
◎ For starting a new add-on module from scratch
- napi.inspiredware.com/getting-started/first.html
◎ For starting a new add-on module from scratch with
ObjectWrap
- napi.inspiredware.com/getting-started/objectwrap.html
◎ For migrating an existing NAN module
- napi.inspiredware.com/getting-started/migration.html
◎ Async Worker
- napi.inspiredware.com/special-topics/asyncworker.html
◎ Node pre-gyp
- napi.inspiredware.com/special-topics/node-pre-gyp.html
Online Tutorials
◎ Prebuild
- napi.inspiredware.com/build-tools/prebuild.html
◎ CMake.js
- napi.inspiredware.com/build-tools/cmake-js.html
◎ Thread-Safe Functions
- napi.inspiredware.com/special-topics/thread-safe-functions.html
◎ Context awareness
- napi.inspiredware.com/special-topics/context-awareness.html
Opportunity to work
on individual projects
Opportunity to work on individual projects
Workshop presenters available for help and questions
N-API Tutorial
http://bit.ly/2P7HfdK
List of add-ons to port
http://bit.ly/2P80VxT
Supporting
resources
Supporting resources
◎ N-API Documentation
- https://nodejs.org/api/n-api.html — The C API
- https://github.com/nodejs/node-addon-api — The C++ wrapper
◎ N-API migration assistant
- https://github.com/nodejs/node-addon-api/blob/master/doc/conversion-tool.md
◎ Generator
- https://www.npmjs.com/package/generator-napi-module
◎ Examples
- https://github.com/nodejs/node-addon-examples/
◎ Node-pre-gyp Documentation
- https://github.com/mapbox/node-pre-gyp
Supporting resources
◎ Prebuild
- https://www.npmjs.com/package/prebuild
◎ Prebuildify
- https://www.npmjs.com/package/prebuildify
◎ CMake.js
- https://www.npmjs.com/package/cmake-js
◎ Other N-API bindings:
- Neon https://github.com/neon-bindings/neon (Rust)
◎ Genepi(Automatic generation of N-API wrapper from a C++ library )
- https://github.com/Geode-solutions/genepi
Wrap-up and assessment
◎ What did you like/not like
- Workshop
- N-API
◎ Get Involved:
- https://github.com/nodejs/abi-stable-node
- https://github.com/nodejs/node
- https://github.com/nodejs/node-addon-api
- Weekly N-API meeting - Monday 08:00 AM Pacific Time (PT)
Next Generation N-API

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React NativeWaqqas Jabbar
 
Wallace Wilhoite - Your Lambda function, your IDE, let’s debug live
Wallace Wilhoite - Your Lambda function, your IDE, let’s debug liveWallace Wilhoite - Your Lambda function, your IDE, let’s debug live
Wallace Wilhoite - Your Lambda function, your IDE, let’s debug liveAWS Chicago
 
EuroPython 2017 - How to make money with your Python open-source project
EuroPython 2017 - How to make money with your Python open-source projectEuroPython 2017 - How to make money with your Python open-source project
EuroPython 2017 - How to make money with your Python open-source projectMax Tepkeev
 
45 Tools to Boost Your Front-End
45 Tools to Boost Your Front-End45 Tools to Boost Your Front-End
45 Tools to Boost Your Front-EndNicolas PENNEC
 
Ratpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsRatpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsJames Williams
 
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...Caktus Group
 
gRPC:更高效的微服務介面
gRPC:更高效的微服務介面gRPC:更高效的微服務介面
gRPC:更高效的微服務介面William Yeh
 
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 JDKSwagger API
 
Multi-cloud CI/CD with failover powered by K8s, Istio, Helm, and Codefresh
Multi-cloud CI/CD with failover powered by K8s, Istio, Helm, and Codefresh Multi-cloud CI/CD with failover powered by K8s, Istio, Helm, and Codefresh
Multi-cloud CI/CD with failover powered by K8s, Istio, Helm, and Codefresh Codefresh
 
給 RD 的 Kubernetes 初體驗 (GDG Cloud KH 2019-08 version)
給 RD 的 Kubernetes 初體驗 (GDG Cloud KH 2019-08 version) 給 RD 的 Kubernetes 初體驗 (GDG Cloud KH 2019-08 version)
給 RD 的 Kubernetes 初體驗 (GDG Cloud KH 2019-08 version) William Yeh
 
From a native app to a webapp using Node.js and emscripten
From a native app to a webapp using Node.js and emscriptenFrom a native app to a webapp using Node.js and emscripten
From a native app to a webapp using Node.js and emscriptenFlorian Rival
 
JHipster overview and roadmap (August 2017)
JHipster overview and roadmap (August 2017)JHipster overview and roadmap (August 2017)
JHipster overview and roadmap (August 2017)Julien Dubois
 
Secrets of Successful Digital Transformers
Secrets of Successful Digital TransformersSecrets of Successful Digital Transformers
Secrets of Successful Digital TransformersVMware Tanzu
 
NativeScript Developer Day Keynote - Todd Anglin & Burke Holland
NativeScript Developer Day Keynote - Todd Anglin & Burke HollandNativeScript Developer Day Keynote - Todd Anglin & Burke Holland
NativeScript Developer Day Keynote - Todd Anglin & Burke HollandBrian Rinaldi
 
Angular 2 - Core Concepts
Angular 2 - Core ConceptsAngular 2 - Core Concepts
Angular 2 - Core ConceptsFabio Biondi
 
ng4 webpack and yarn in JHipster
ng4 webpack and yarn in JHipsterng4 webpack and yarn in JHipster
ng4 webpack and yarn in JHipsterSendil Kumar
 
Gradle,the new build system for android
Gradle,the new build system for androidGradle,the new build system for android
Gradle,the new build system for androidzhang ghui
 
Angular2 & Native Script GDG DevFest 2016
Angular2 & Native Script GDG DevFest 2016Angular2 & Native Script GDG DevFest 2016
Angular2 & Native Script GDG DevFest 2016Luciano Murruni
 
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 InflectorTony Tam
 

Was ist angesagt? (20)

Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
Wallace Wilhoite - Your Lambda function, your IDE, let’s debug live
Wallace Wilhoite - Your Lambda function, your IDE, let’s debug liveWallace Wilhoite - Your Lambda function, your IDE, let’s debug live
Wallace Wilhoite - Your Lambda function, your IDE, let’s debug live
 
EuroPython 2017 - How to make money with your Python open-source project
EuroPython 2017 - How to make money with your Python open-source projectEuroPython 2017 - How to make money with your Python open-source project
EuroPython 2017 - How to make money with your Python open-source project
 
45 Tools to Boost Your Front-End
45 Tools to Boost Your Front-End45 Tools to Boost Your Front-End
45 Tools to Boost Your Front-End
 
Ratpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsRatpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web Apps
 
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
 
gRPC:更高效的微服務介面
gRPC:更高效的微服務介面gRPC:更高效的微服務介面
gRPC:更高效的微服務介面
 
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
 
Angular 2
Angular 2Angular 2
Angular 2
 
Multi-cloud CI/CD with failover powered by K8s, Istio, Helm, and Codefresh
Multi-cloud CI/CD with failover powered by K8s, Istio, Helm, and Codefresh Multi-cloud CI/CD with failover powered by K8s, Istio, Helm, and Codefresh
Multi-cloud CI/CD with failover powered by K8s, Istio, Helm, and Codefresh
 
給 RD 的 Kubernetes 初體驗 (GDG Cloud KH 2019-08 version)
給 RD 的 Kubernetes 初體驗 (GDG Cloud KH 2019-08 version) 給 RD 的 Kubernetes 初體驗 (GDG Cloud KH 2019-08 version)
給 RD 的 Kubernetes 初體驗 (GDG Cloud KH 2019-08 version)
 
From a native app to a webapp using Node.js and emscripten
From a native app to a webapp using Node.js and emscriptenFrom a native app to a webapp using Node.js and emscripten
From a native app to a webapp using Node.js and emscripten
 
JHipster overview and roadmap (August 2017)
JHipster overview and roadmap (August 2017)JHipster overview and roadmap (August 2017)
JHipster overview and roadmap (August 2017)
 
Secrets of Successful Digital Transformers
Secrets of Successful Digital TransformersSecrets of Successful Digital Transformers
Secrets of Successful Digital Transformers
 
NativeScript Developer Day Keynote - Todd Anglin & Burke Holland
NativeScript Developer Day Keynote - Todd Anglin & Burke HollandNativeScript Developer Day Keynote - Todd Anglin & Burke Holland
NativeScript Developer Day Keynote - Todd Anglin & Burke Holland
 
Angular 2 - Core Concepts
Angular 2 - Core ConceptsAngular 2 - Core Concepts
Angular 2 - Core Concepts
 
ng4 webpack and yarn in JHipster
ng4 webpack and yarn in JHipsterng4 webpack and yarn in JHipster
ng4 webpack and yarn in JHipster
 
Gradle,the new build system for android
Gradle,the new build system for androidGradle,the new build system for android
Gradle,the new build system for android
 
Angular2 & Native Script GDG DevFest 2016
Angular2 & Native Script GDG DevFest 2016Angular2 & Native Script GDG DevFest 2016
Angular2 & Native Script GDG DevFest 2016
 
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
 

Ähnlich wie Next Generation N-API

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
 
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for RustJS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for RustJSFestUA
 
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
 
Angular based enterprise level frontend architecture
Angular based enterprise level frontend architectureAngular based enterprise level frontend architecture
Angular based enterprise level frontend architectureHimanshu Tamrakar
 
Angular4 getting started
Angular4 getting startedAngular4 getting started
Angular4 getting startedTejinderMakkar
 
Knative And Pivotal Function As a Service
Knative And Pivotal Function As a ServiceKnative And Pivotal Function As a Service
Knative And Pivotal Function As a ServiceJay Lee
 
WebSDK - Switching between service providers
WebSDK - Switching between service providersWebSDK - Switching between service providers
WebSDK - Switching between service providersHotstar
 
New Features of Kubernetes v1.2.0 beta
New Features of Kubernetes v1.2.0 betaNew Features of Kubernetes v1.2.0 beta
New Features of Kubernetes v1.2.0 betaGiragadurai Vallirajan
 
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
 
A Real ADF Experience Part II
A Real ADF Experience Part IIA Real ADF Experience Part II
A Real ADF Experience Part IIMano Swerts
 
Front matter: Next Level Front End Deployments on OpenShift
Front matter: Next Level Front End Deployments on OpenShiftFront matter: Next Level Front End Deployments on OpenShift
Front matter: Next Level Front End Deployments on OpenShiftLance Ball
 
The path to a serverless-native era with Kubernetes
The path to a serverless-native era with KubernetesThe path to a serverless-native era with Kubernetes
The path to a serverless-native era with Kubernetessparkfabrik
 
Kubernetes for Java Developers
 Kubernetes for Java Developers Kubernetes for Java Developers
Kubernetes for Java DevelopersRed Hat Developers
 
JavaOne 2016: Kubernetes introduction for Java Developers
JavaOne 2016: Kubernetes introduction for Java Developers JavaOne 2016: Kubernetes introduction for Java Developers
JavaOne 2016: Kubernetes introduction for Java Developers Rafael Benevides
 
Build a RESTful API with the Serverless Framework
Build a RESTful API with the Serverless FrameworkBuild a RESTful API with the Serverless Framework
Build a RESTful API with the Serverless Frameworkmasahitojp
 
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
 
NodeWay in my project & sails.js
NodeWay in my project & sails.jsNodeWay in my project & sails.js
NodeWay in my project & sails.jsDmytro Ovcharenko
 

Ähnlich wie Next Generation N-API (20)

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...
 
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for RustJS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
 
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?
 
Angular based enterprise level frontend architecture
Angular based enterprise level frontend architectureAngular based enterprise level frontend architecture
Angular based enterprise level frontend architecture
 
Angular4 getting started
Angular4 getting startedAngular4 getting started
Angular4 getting started
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 
Knative And Pivotal Function As a Service
Knative And Pivotal Function As a ServiceKnative And Pivotal Function As a Service
Knative And Pivotal Function As a Service
 
WebSDK - Switching between service providers
WebSDK - Switching between service providersWebSDK - Switching between service providers
WebSDK - Switching between service providers
 
How to Enterprise Node
How to Enterprise NodeHow to Enterprise Node
How to Enterprise Node
 
New Features of Kubernetes v1.2.0 beta
New Features of Kubernetes v1.2.0 betaNew Features of Kubernetes v1.2.0 beta
New Features of Kubernetes v1.2.0 beta
 
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...
 
A Real ADF Experience Part II
A Real ADF Experience Part IIA Real ADF Experience Part II
A Real ADF Experience Part II
 
Front matter: Next Level Front End Deployments on OpenShift
Front matter: Next Level Front End Deployments on OpenShiftFront matter: Next Level Front End Deployments on OpenShift
Front matter: Next Level Front End Deployments on OpenShift
 
The path to a serverless-native era with Kubernetes
The path to a serverless-native era with KubernetesThe path to a serverless-native era with Kubernetes
The path to a serverless-native era with Kubernetes
 
Kubernetes for Java Developers
 Kubernetes for Java Developers Kubernetes for Java Developers
Kubernetes for Java Developers
 
JavaOne 2016: Kubernetes introduction for Java Developers
JavaOne 2016: Kubernetes introduction for Java Developers JavaOne 2016: Kubernetes introduction for Java Developers
JavaOne 2016: Kubernetes introduction for Java Developers
 
Build a RESTful API with the Serverless Framework
Build a RESTful API with the Serverless FrameworkBuild a RESTful API with the Serverless Framework
Build a RESTful API with the Serverless Framework
 
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)
 
NodeWay in my project & sails.js
NodeWay in my project & sails.jsNodeWay in my project & sails.js
NodeWay in my project & sails.js
 
Nodejs overview
Nodejs overviewNodejs overview
Nodejs overview
 

Mehr von Nicola Del Gobbo

Expressjs from-zero-to-hero
Expressjs from-zero-to-heroExpressjs from-zero-to-hero
Expressjs from-zero-to-heroNicola Del Gobbo
 
Lexgenda Documenti d’archivio e nuove tecnologie
Lexgenda Documenti d’archivio e nuove tecnologieLexgenda Documenti d’archivio e nuove tecnologie
Lexgenda Documenti d’archivio e nuove tecnologieNicola Del Gobbo
 
Automatic generation of inspection checklist by user profiling
Automatic generation of inspection checklist by user profilingAutomatic generation of inspection checklist by user profiling
Automatic generation of inspection checklist by user profilingNicola Del Gobbo
 

Mehr von Nicola Del Gobbo (7)

Nodejs from zero to hero
Nodejs from zero to heroNodejs from zero to hero
Nodejs from zero to hero
 
Expressjs from-zero-to-hero
Expressjs from-zero-to-heroExpressjs from-zero-to-hero
Expressjs from-zero-to-hero
 
Introduzione a Node.js
Introduzione a Node.jsIntroduzione a Node.js
Introduzione a Node.js
 
Node js with steroids
Node js with steroidsNode js with steroids
Node js with steroids
 
Lexgenda Documenti d’archivio e nuove tecnologie
Lexgenda Documenti d’archivio e nuove tecnologieLexgenda Documenti d’archivio e nuove tecnologie
Lexgenda Documenti d’archivio e nuove tecnologie
 
Automatic generation of inspection checklist by user profiling
Automatic generation of inspection checklist by user profilingAutomatic generation of inspection checklist by user profiling
Automatic generation of inspection checklist by user profiling
 
Lexgenda
LexgendaLexgenda
Lexgenda
 

Kürzlich hochgeladen

Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 

Kürzlich hochgeladen (20)

Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 

Next Generation N-API

  • 1. Next Generation N-API A hands-on workshop N-API Team
  • 2. Works at Intel Involved with the API working group - Technical Steering Committee (TSC) member - Promises - Exception handling - Environment propagation - Module loading - Wrap/Unwrap - Thread-safe function Gabriel Schulhof @gabrielschulhof gabriel.schulhof@intel.com About Gabriel Schulhof
  • 3. IBM Community Lead for Node.js Active Node.js community member - Technical Steering Committee (TSC) member - Community Committee member - n-api, build, security, benchmarking, diagnostics, release, user-feedback, teams and WGs. Michael Dawson @mhdawson1 @mhdawson About Michael Dawson
  • 4. President of inspiredware Member of the N-API Team - node-pre-gyp - Prebuild - Documentation Jim Schlight @inspiredware @jschlight About Jim Schlight
  • 5. Developer at Packly Member of the N-API Team Nicola Del Gobbo @NickNaso @NickNaso About Nicola Del Gobbo
  • 6. Anna Henningsen @addaleax Gabriel Schulhof @gabrielschulhof Hitesh Kanwathirtha @digitalinfinity Jim Schlight @jschlight Michael Dawson @mhdawson Nicola Del Gobbo @NickNaso Kevin Eady @KevinEady Arunesh Chandra @aruneshchandra Taylor Wall @boingoing Anisha Rohra @anisha-rohra Kyle Farnung @kfarnung And many others ... Contributors
  • 8. Orientation to N-API Awareness of available tools and processes A good start on your own projects
  • 10. 1. Introduction to N-API and node-addon-api 2. Online tutorials 3. Let’s port some modules/individual projects 4. Wrap-up and assessment
  • 12. What is a native addon? Node.js addons are dynamically-linked shared objects, written in C or C++, that can be loaded into Node.js using therequire() function, and used just as if they were an ordinaryNode.js module They are used primarily to provide an interface between JavaScript running in Node.js and C/C++ libraries
  • 13. What is a native addon?
  • 15. Motivations for N-API The API to implement native add-ons has been changed across different version of Node.js Most of the changes were on V8 API and ObjectWrap API and other node internals About 30% of modules depend on a native add-on. A breakage on a native addon could become very important e.g. node-sass
  • 16. Motivations for N-API Need an adapter to stay compatible across different versions of Node.js NAN - Native Abstraction for Node.js - API compatibility - Strongly bonded with V8 API - You have to recompile your native add-ons when switching to a different version of Node.js
  • 17. Motivations for N-API End user Maintainers
  • 19. What’s N-API ◎ Abstraction of the underlying JavaScript engine ◎ Defines and exports C types and functions that are independent from the JavaScript engine ◎ A binary-stable ABI
  • 21. Without N-API Addon Node.js: 6.12.2 V8: 5.1.281 NODE_MODULE_VERSION: 48
  • 22. Node.js: 8.9.3 V8: 6.1.534 NODE_MODULE_VERSION: 57 Without N-API ● ABI break ○ At worst, mysterious segfaults ○ At best, addon fails to load ○ NODE_MODULE_VERSION mismatch
  • 23. Node.js: no matter V8/ChakraCore: no matter NAPI_VERSION: 1 With N-API
  • 24. Node.js: later V8/ChakraCore: no matter NAPI_VERSION: 2 With N-API ● No ABI break ○ NAPI_VERSION is cumulative ○ Addon is forwards compatible
  • 27. Context Awareness Cleanup ◎ Unload DSO (one per process) ◎ Unload addon instance data - napi_add_env_cleanup_hook() – N-API 5 - napi_set_instance_data() – experimental ◎ Clean up leftover references created with - napi_wrap() - napi_add_finalizer() – N-API 5 - napi_buffer_create_external() - et. al. GC will not free them! Need to track them and explicitly free them!
  • 29. A brief history of N-API
  • 31. N-API and node-addon-api ◎ N-API is C whereas node-addon-api is C++ ◎ node-addon-api not technically part of ABI stable API - Helper to simplify code using C++ - All inline - Only depends on export N-API C functions npm install node-addon-api About 300k downloads / week
  • 34. Node-addon-api Versus NAN ◎ Same - Includes a C++ wrapper - Provides common helper functionality - Reduces likelihood of needing to change code for new Node.js versions ◎ Different - Does not use V8 Types - Not tied to a specific JavaScript engine - Preserves compile once/run multiple versions from N-API - Reduces even further likelihood of having to change code
  • 35. What happened in the last year core - node-addon-api - tools
  • 36. What happened in the last year (core) ◎ N-API 4 - Added thread-safe function ◎ N-API 5 - Added API to manage date object - Finalizer callback (marked as stable) - Optional callback in thread-safe function - Added reference cleanup
  • 37. What happened in the last year (node-addon-api) ◎ Improved documentation ◎ Added new asynchronous API - Napi::AsyncContext ◎ Added thread-safe function - Napi::ThreadsafeFunction ◎ Improved AsyncWorker API - See: https://github.com/nodejs/node-addon-api/issues/231 ◎ Added AsyncProgressWorker API - Napi::AsyncProgressWorker ◎ Added API to manage date object - Napi::Date
  • 38. What happened in the last year (tools) ◎ Added support for prebuild - A command line tool for easily making prebuilt binaries - https://www.npmjs.com/package/prebuild#n-api-considerations ◎ Added support for cmake-js - Build tool that uses CMake to build the native add-on instead of GYP - https://www.npmjs.com/package/cmake-js#n-api-and-node-addon- api
  • 40. How to organize your project ◎ build folder contains the intermediary and final build products. ◎ lib folder contains the the JavaScript code that will use the native code to export some features ◎ src folder contains the native C / C++ code ◎ test folder contains the testing code ◎ binding.gyp file that contains all settings to build the native add-on ◎ package.json npm description of your module ◎ package-lock.json used by npm to ensure deployment consistency
  • 42. What’s binding.gyp By default Node.js use GYP to build the native add-on(s). Native add-ons are built using node-gyp, a cross platform CLI tool written in Node.js that contains a fork of GYP. GYP https://gyp.gsrc.io node-gyp https://github.com/nodejs/node- gyp There are other build tools like cmake-js
  • 43. Add a badge to your project
  • 44. Add a badge to your project ◎ Simply add a URL to the top of your README file ◎ Indicates the minimum N-API version your addon supports ◎ Benefits - Identifies your addon as supporting N-API - Makes your addon easier to find ◎ N-API v3 is a good starting point because this is the first version considered as stable API
  • 45. Add a badge to your project https://img.shields.io/badge/N--API-v3-green.svg https://img.shields.io/badge/N--API-v4-green.svg https://img.shields.io/badge/N--API-v5-green.svg https://img.shields.io/badge/N--API-experimental- orange.svg
  • 47. Online Tutorials ◎ For starting a new add-on module from scratch - napi.inspiredware.com/getting-started/first.html ◎ For starting a new add-on module from scratch with ObjectWrap - napi.inspiredware.com/getting-started/objectwrap.html ◎ For migrating an existing NAN module - napi.inspiredware.com/getting-started/migration.html ◎ Async Worker - napi.inspiredware.com/special-topics/asyncworker.html ◎ Node pre-gyp - napi.inspiredware.com/special-topics/node-pre-gyp.html
  • 48. Online Tutorials ◎ Prebuild - napi.inspiredware.com/build-tools/prebuild.html ◎ CMake.js - napi.inspiredware.com/build-tools/cmake-js.html ◎ Thread-Safe Functions - napi.inspiredware.com/special-topics/thread-safe-functions.html ◎ Context awareness - napi.inspiredware.com/special-topics/context-awareness.html
  • 49. Opportunity to work on individual projects
  • 50. Opportunity to work on individual projects Workshop presenters available for help and questions N-API Tutorial http://bit.ly/2P7HfdK List of add-ons to port http://bit.ly/2P80VxT
  • 52. Supporting resources ◎ N-API Documentation - https://nodejs.org/api/n-api.html — The C API - https://github.com/nodejs/node-addon-api — The C++ wrapper ◎ N-API migration assistant - https://github.com/nodejs/node-addon-api/blob/master/doc/conversion-tool.md ◎ Generator - https://www.npmjs.com/package/generator-napi-module ◎ Examples - https://github.com/nodejs/node-addon-examples/ ◎ Node-pre-gyp Documentation - https://github.com/mapbox/node-pre-gyp
  • 53. Supporting resources ◎ Prebuild - https://www.npmjs.com/package/prebuild ◎ Prebuildify - https://www.npmjs.com/package/prebuildify ◎ CMake.js - https://www.npmjs.com/package/cmake-js ◎ Other N-API bindings: - Neon https://github.com/neon-bindings/neon (Rust) ◎ Genepi(Automatic generation of N-API wrapper from a C++ library ) - https://github.com/Geode-solutions/genepi
  • 54. Wrap-up and assessment ◎ What did you like/not like - Workshop - N-API ◎ Get Involved: - https://github.com/nodejs/abi-stable-node - https://github.com/nodejs/node - https://github.com/nodejs/node-addon-api - Weekly N-API meeting - Monday 08:00 AM Pacific Time (PT)