MCPcopy Index your code
hub / github.com/akshayganeshen/napi-go

github.com/akshayganeshen/napi-go @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
146 symbols 291 edges 29 files 6 documented · 4%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

napi-go

A Go library for building Node.js Native Addons using Node-API.

Usage

Use go get to install the library:

go get -u github.com/akshayganeshen/napi-go

Then use the library to define handlers:

package handlers

import "github.com/akshayganeshen/napi-go"

func MyHandler(env napi.Env, info napi.CallbackInfo) napi.Value {
  return nil
}

Next, create a main.go that registers all module exports:

package main

import "github.com/akshayganeshen/napi-go/entry"

func init() {
  entry.Export("myHandler", MyHandler)
}

func main() {}

Finally, build the Node.js addon using go build:

go build -buildmode=c-shared -o "example.node" .

The output .node file can now be imported via require:

const example = require("./example.node");

example.myHandler();

JS Helpers

In addition to the Node-API exposed via package napi, the napi-go/js package provides functions similar to the syscall/js standard library.

package main

import (
  "github.com/akshayganeshen/napi-go/entry"
  "github.com/akshayganeshen/napi-go/js"
)

func init() {
  entry.Export("myCallback", js.AsCallback(MyCallback))
}

func MyCallback(env js.Env, this js.Value, args []js.Value) any {
  return map[string]any{
    "message": "hello world",
    "args":    args,
  }
}

func main() {}

Examples

Check out the example addons in docs/examples.

Extension points exported contracts — how you extend this code

InstanceDataProvider (Interface)
(no doc) [1 implementers]
instance_data.go
PromiseProvider (Interface)
(no doc) [1 implementers]
js/promise.go
Callback (FuncType)
(no doc)
callback.go
AsyncExecuteCallback (FuncType)
(no doc)
async_work.go
CallbackDataProvider (Interface)
(no doc) [1 implementers]
instance_data.go
AsyncCompleteCallback (FuncType)
(no doc)
async_work.go
AsyncWorkDataProvider (Interface)
(no doc) [1 implementers]
instance_data.go

Core symbols most depended-on inside this repo

getInstanceData
called by 9
instance_data.go
Export
called by 9
entry/exports.go
AsCallback
called by 5
js/callback.go
Error
called by 4
status.go
ThrowError
called by 4
js_native_api.go
GetAsyncWorkData
called by 4
instance_data.go
reportStackTrace
called by 4
instance_data.go
ValueOf
called by 4
js/env.go

Shape

Function 71
Method 40
Struct 15
TypeAlias 13
Interface 4
FuncType 3

Languages

Go100%

Modules by API surface

instance_data.go44 symbols
js_native_api.go28 symbols
js/promise.go11 symbols
node_api.go10 symbols
js/env.go10 symbols
docs/examples/js/main.go7 symbols
status.go4 symbols
docs/examples/describe-args/main.go4 symbols
docs/examples/hello-world/main.go3 symbols
docs/examples/callback/main.go3 symbols
docs/examples/async-promise/main.go3 symbols
async_work.go3 symbols

For agents

$ claude mcp add napi-go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact