Skip to main content

Nitro Modules

A Nitro Module is a library built with Nitro. It may contain one or more Hybrid Objects.

Structure

A Nitro Module contains the usual react-native library structure, with ios/ and android/ folders, a package.json, and a *.podspec file for iOS. In addition to the base react-native library template, a Nitro Module also contains:

  • A TypeScript setup
  • A nitro.json configuration file

Creating a Nitro Module

1. Download the template

The mrousavy/nitro repository contains a template (packages/template) which can be used to create a new Nitro Module:

git clone https://github.com/mrousavy/nitro /tmp/nitro
cp -R /tmp/nitro/packages/template my-new-library

2. Replace all placeholders

You need to replace all <<*>> placeholders and filenames for each value in nitro.json. For example, <<iosModulename>> can be replaced with NitroMath:

NitroMath.podspec
...
Pod::Spec.new do |s|
s.name = "<<iosModulename>>"
s.name = "NitroMath"
...

3. Set up an example app

After properly creating a Nitro Module, it's time to set up an example app to test your library:

npx create-expo-app@latest

4. Implement your Hybrid Objects

Once you set up the library, you can start implementing your Hybrid Objects!

With Nitrogen you can ✨ automagically ✨ generate all native interfaces from your TypeScript definitions. After implementing the generated specs, register them using the HybridObjectRegistry.

See Hybrid Objects (Implementation) for more information.

tip

In a future version of Nitro, Nitrogen will be able to bootstrap a Nitro Module template with a simple command to avoid this manual configuration.