Skip to main content

Configuration (nitro.json)

Nitrogen requires a nitro.json file to be configured at the root of each Nitro Module.

{
"$schema": "https://nitro.margelo.com/nitro.schema.json",
"environment": "react-native",
"cxxNamespace": ["$$cxxNamespace$$"],
"ios": {
"iosModuleName": "$$iosModuleName$$"
},
"android": {
"androidNamespace": ["$$androidNamespace$$"],
"androidCxxLibName": "$$androidCxxLibName$$"
},
"ignorePaths": ["**/node_modules"]
}

Nitrogen parses this file with Zod, see NitroUserConfig.ts for more information.

environment​

Selects the package that generated JavaScript code imports Nitro APIs from:

  • "react-native" (default): imports from react-native-nitro-modules, which installs Nitro in the React Native runtime.
  • "bare": imports from nitro-core for standalone runtimes.

This setting only changes the JavaScript imports. Native code generation is the same for both environments.

cxxNamespace​

The cxxNamespace is the C++ namespace that all C++ specs will be generated in. It is always relative to margelo::nitro, and can also have multiple sub-namespaces:

{
"cxxNamespace": ["math", "extra"]
}
namespace margelo::nitro::math::extra {
// ...generated classes
}

ios​

Settings specifically for the iOS platform.

iosModuleName​

The iosModuleName names the generated Swift module and SwiftPM library product. Use the same name in your library's swiftpmConfig:

{
"ios": {
"iosModuleName": "NitroMath"
}
}
package.json
{
"swiftpmConfig": {
"name": "NitroMath",
"dependencies": ["react-native-nitro-modules"]
}
}

See Nitrogen's build setup for Package.swift and generated source configuration.

android​

Settings specifically for the Android platform.

androidNamespace​

The androidNamespace represents the package namespace in which all Java/Kotlin files are generated and written in. Similar to the cxxNamespace, this is always relative to com.margelo.nitro, and can also have multiple sub-namespaces.

In most cases, you should keep this in sync with the namespace specified in your build.gradle.

{
"android": {
"androidNamespace": ["math", "extra"]
}
}
package com.margelo.nitro.math.extra

// ...

androidCxxLibName​

The androidCxxLibName represents the name of the native C++ library that JNI will load to connect Java/Kotlin to C++.

When this Nitro Module is using CMake, this is the same thing as the library defined in CMakeLists.txt. Nitro will load this library at runtime using System.loadLibrary.

{
"android": {
"androidCxxLibName": "NitroMath"
}
}
project(NitroMath)
add_library(NitroMath SHARED
src/main/cpp/cpp-adapter.cpp
../cpp/HybridMath.cpp
)

ignorePaths​

Configures the TypeScript parser to ignore specific given paths when looking for *.nitro.ts specs.

By default, this is empty ([]), but it can be set to ignore paths like ["node_modules", "lib"].