npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-nitro-restart

v0.1.1

Published

App restart and process management for React Native built with Nitro Modules. Provides native app restart, safe exit, and process ID functionality with cross-platform support for iOS and Android.

Readme

react-native-nitro-restart

App restart and process management for React Native built with Nitro Modules.

Overview

This module provides native-level app restart and process management functionality for both Android and iOS. It exposes simple JS/TS APIs to restart the app, exit the app, and get the current process ID.

Features

  • App Restart - Restart the entire React Native app
  • App Exit - Safely exit the application
  • 🆔 Process ID - Get the current process identifier
  • 🚀 Built with Nitro Modules for native performance and autolinking support
  • 📱 Cross-platform support (iOS & Android)
  • ⚡ Zero-config setup with autolinking

Requirements

  • React Native >= 0.76
  • Node >= 18
  • react-native-nitro-modules must be installed (Nitro runtime)

Installation

npm install react-native-nitro-restart react-native-nitro-modules
# or
yarn add react-native-nitro-restart react-native-nitro-modules

Configuration

Android Setup

No additional configuration required. The module will automatically handle app restart through Android's activity management.

iOS Setup

No additional configuration required. The module uses React Native's built-in restart capabilities.

Troubleshooting

  • Android: If restart doesn't work, ensure your app has proper activity lifecycle management
  • iOS: Make sure your app delegate is properly configured for React Native
  • Both platforms: Test on real devices for best results

Quick Usage

import { NitroRestartModule } from 'react-native-nitro-restart'

// Restart the app with default module name
NitroRestartModule.restartApp('YourAppName')

// Get current process ID
const processId = NitroRestartModule.getPid()
console.log('Current PID:', processId)

// Exit the app (use with caution)
NitroRestartModule.exitApp()

API Reference

App Management

restartApp(moduleName: string): void

Restarts the React Native application with the specified module name.

Parameters:

  • moduleName (string): The name of the main React Native module to restart with

Example:

import { NitroRestartModule } from 'react-native-nitro-restart'

// Restart with your app's main module
NitroRestartModule.restartApp('MyApp')

exitApp(): void

Safely exits the application. On iOS, this moves the app to background instead of force terminating. On Android, this finishes the current activity and moves the app to background.

Note: Use this method with caution as it may violate app store guidelines if used inappropriately.

Example:

import { NitroRestartModule } from 'react-native-nitro-restart'

// Exit the app
NitroRestartModule.exitApp()

getPid(): number

Returns the current process identifier (PID) of the application.

Returns:

  • number: The current process ID

Example:

import { NitroRestartModule } from 'react-native-nitro-restart'

// Get current process ID
const processId = NitroRestartModule.getPid()
console.log('Current PID:', processId)

Complete Example

import React, { useState } from 'react'
import { View, Button, Text, Alert } from 'react-native'
import { NitroRestartModule } from 'react-native-nitro-restart'

const App = () => {
  const [processId, setProcessId] = useState<number | null>(null)

  const handleGetPid = () => {
    const pid = NitroRestartModule.getPid()
    setProcessId(pid)
  }

  const handleRestart = () => {
    Alert.alert(
      'Restart App',
      'Are you sure you want to restart the application?',
      [
        { text: 'Cancel', style: 'cancel' },
        {
          text: 'Restart',
          onPress: () => NitroRestartModule.restartApp('YourAppName')
        }
      ]
    )
  }

  const handleExit = () => {
    Alert.alert(
      'Exit App',
      'Are you sure you want to exit the application?',
      [
        { text: 'Cancel', style: 'cancel' },
        {
          text: 'Exit',
          style: 'destructive',
          onPress: () => NitroRestartModule.exitApp()
        }
      ]
    )
  }

  return (
    <View style={{ flex: 1, justifyContent: 'center', padding: 20 }}>
      <Button title="Get Process ID" onPress={handleGetPid} />
      {processId && (
        <Text style={{ textAlign: 'center', margin: 10 }}>
          Current PID: {processId}
        </Text>
      )}
      
      <Button title="Restart App" onPress={handleRestart} />
      <Button title="Exit App" onPress={handleExit} color="red" />
    </View>
  )
}

export default App

Platform Support

| Feature | iOS | Android | Notes | | ------------ | --- | ------- | ----- | | restartApp() | ✅ | ✅ | Creates new React context | | exitApp() | ✅ | ✅ | Moves to background (safe) | | getPid() | ✅ | ✅ | Returns process identifier |

Best Practices

  1. User confirmation: Always ask for user confirmation before restarting or exiting the app
  2. Save state: Ensure important app state is saved before restart/exit operations
  3. Error handling: Wrap operations in try-catch blocks for production apps
  4. App store compliance: Be cautious with exitApp() - some app stores discourage apps from terminating themselves
  5. Testing: Test restart functionality thoroughly on both platforms and different devices

Important Notes

⚠️ App Store Guidelines:

  • iOS: Apple's guidelines discourage apps from programmatically terminating themselves
  • Android: Google Play has similar recommendations
  • Use exitApp() sparingly and only when absolutely necessary

📱 Platform Differences:

  • iOS: Restart creates a new React Native context within the same process
  • Android: Restart may create a new activity or recreate the React context
  • Both platforms handle exitApp() by moving the app to background instead of force termination

TypeScript Interface

export interface NitroRestart
  extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
  restartApp(moduleName: string): void
  exitApp(): void
  getPid(): number
}

Migration Notes

When updating spec files in src/specs/*.nitro.ts, regenerate Nitro artifacts:

npx nitro-codegen

Contributing

See CONTRIBUTING.md for contribution workflow. Run npx nitro-codegen after editing spec files.

Project Structure

  • android/ — Native Android implementation (Kotlin)
  • ios/ — Native iOS implementation (Swift)
  • src/ — TypeScript API exports
  • nitrogen/ — Generated Nitro artifacts

Acknowledgements

Special thanks to the following open-source projects which inspired and supported the development of this library:

License

MIT © Thành Công