Skip to content

A simple Node.js native addon using N-API to call a C addition function from JavaScript

Notifications You must be signed in to change notification settings

iamswethaa/native-addon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Native Addon: Addition Function (N-API with node_api.h)

This project demonstrates how to use N-API with node_api.h to call a C function (addition) from JavaScript.

Project Structure

  native-addon/
  ├── addon.c
  ├── binding.gyp
  ├── index.js
  ├── package.json
  ├── package-lock.json
  └── README.md

Description

  • addon.c : N-API wrapper that contains the native C function int add(int a, int b) and bridges add() to JavaScript.

  • index.js : JavaScript file that uses the native addon.

  • binding.gyp : Build configuration for node-gyp.

Build Instructions

1. Install node-gyp if not already installed

npm install -g node-gyp

2. Initialize and build the addon

npm install
node-gyp configure
node-gyp build

The compiled addon will be created in the build/Release/ folder.

Run Script

node index.js

About

A simple Node.js native addon using N-API to call a C addition function from JavaScript

Topics

Resources

Stars

Watchers

Forks