React Native Node is a powerful library that enables running a full Node.js process in the background of a React Native Android application. It provides a unique solution for developers who need to leverage Node.js capabilities within a mobile React Native environment.
The library allows developers to:
- Run a complete Node.js process alongside a React Native app
- Execute Node.js functionality that is typically unavailable in mobile JavaScript environments
- Off-load heavy processing from the main JavaScript thread
- Interface with the file system
- Run HTTP servers directly from the mobile application
- Seamless integration with React Native
- Runs a real Node.js process (v7.1.0) using V8 engine
- Supports background processing
- Enables use of Node.js streams
- Provides method to start and stop the Node.js background process
- Compresses and bundles the Node.js application into the mobile app
- Deprecated: The project is no longer actively maintained
- Currently supports Android only
- iOS support is not available due to platform restrictions
- Limited support for packages with native bindings
- React Native (version 0.47.0 or higher)
- npm or yarn
- Android development environment
Install the package using npm or yarn:
npm install --save react-native-node
# or
yarn add react-native-nodeLink the native module:
react-native link react-native-node-
Create a background Node.js project (e.g., in a
./backgrounddirectory) -
In your React Native app, import and use the module:
import RNNode from "react-native-node";
class MyApp extends Component {
componentDidMount() {
// Start the background Node.js process
RNNode.start();
// Optionally, pass arguments to the process
// RNNode.start(['--color', 'red', '--port', '3000'])
}
componentWillUnmount() {
// Stop the background process when no longer needed
RNNode.stop();
}
}- Bundle your background application:
./node_modules/.bin/react-native-node insert ./backgroundThis command does two things:
- Compresses your background app into
./android/app/src/main/res/raw/rnnodebundle - Updates
AndroidManifest.xmlto include a Service class
- Build and run your mobile app:
react-native run-android- Fully supported using Node.js v7.1.0 with V8
- Requires Android development environment
- Not supported due to Apple's restrictions on Just-In-Time compilation
To debug the Node.js process, use adb logcat with specific tags:
adb logcat *:S nodejs:V RNNodeThread:V RNNodeService:V- This library is DEPRECATED
- Consider using Node.js Mobile as an alternative
- Most suitable for Android development
- Supports Node.js packages, but native bindings may require additional configuration
There are no exported constants in this library.
Starts the Node.js runtime within the mobile application.
- Parameters:
args(optional): An array of command-line arguments to pass to Node.js. If not an array, an empty array will be used.
- Returns:
void
Example:
import RNNode from 'react-native-node';
// Start Node.js with no arguments
RNNode.start();
// Start Node.js with specific arguments
RNNode.start(['-e', 'console.log("Hello from Node.js")']);Stops the Node.js runtime that was previously started.
- Parameters: None
- Returns:
void
Example:
import RNNode from 'react-native-node';
RNNode.stop();The library also exports the RNNode module as its default export, which is equivalent to the named export.
Example:
import RNNode from 'react-native-node';
// or
import { RNNode } from 'react-native-node';
// Both forms can be used interchangeably
RNNode.start();The project is organized into several key directories and files:
bin.js: Core script for the main functionalityindex.js: Main entry point for the projectpackage.json: Project configuration and dependenciesLICENSE: Project licensing informationCHANGELOG.md: Version history and changes
The android/ directory contains Android-specific implementation:
android/build.gradle: Android build configurationandroid/src/main/java/com/staltz/reactnativenode/: Contains Java classes for React Native Node moduleRNNodeModule.java: Main module implementationRNNodePackage.java: Package configurationRNNodeService.java: Service-related functionalityRNNodeThread.java: Threading implementation
The example/ directory provides a sample implementation:
example/index.android.js: Example Android entry pointexample/background/: Background processing exampleexample/android/: Example Android project structureexample/android/app/: Contains Android app-specific filesexample/android/app/src/main/java/com/example/: MainActivity and MainApplication
.eslintrc: ESLint configuration for code linting.flowconfig: Flow type checking configuration.npmignoreand.gitignore: Exclusion rules for npm and git
- React Native: Mobile application framework (peer dependency)
- Node.js: Version 7.1.0, used for background processing
- V8 JavaScript Engine: Used for Node.js runtime
- JavaScript
- Java (for Android implementation)
- cheerio: HTML parsing and manipulation library
- mkdirp: Directory creation utility
- path: File path manipulation
- tar: Tar archive manipulation
- yargs: Command-line argument parsing
- ESLint: Code linting
- Babel: JavaScript transpilation
- Android (primary supported platform)
- Gradle (for Android build process)
- npm/yarn for package management
- Background Node.js process running in React Native
- Native Node.js binary compilation
- Service-based background processing
- Deprecation Notice: This library is no longer actively maintained. The recommended alternative is Node.js Mobile by Janea Systems.
When working with this library, use adb logcat with specific tags to diagnose issues:
adb logcat *:S nodejs:V ReactNative:V ReactNativeJS:V
Key logging tags:
RNNodeThread: Process start, termination, and error eventsRNNodeService: Debug information for tar/untar and Node binary preparationRNNode: General library-related logging
To reduce the size of the rnnodebundle file, consider using tools like noderify to create a single JavaScript file.
- Node.js Version: Uses Node.js v7.1.0 with V8 engine
- Platform Support:
- Android: Fully supported
- iOS: Not supported due to Apple's restrictions on Just-In-Time compilation
While the library supports packages with native bindings in theory, compatibility depends on individual library implementations. For complex native compilations, consider using termux on an Android device for direct compilation.
This library was primarily developed to support the Scuttlebutt ecosystem, specifically for the mobile app project mmmmm.
We welcome contributions to the React Native Node project! Here are some guidelines to help you contribute effectively:
- Bug reports and feature suggestions via GitHub Issues
- Pull requests for bug fixes, improvements, or new features
- Documentation enhancements
- Code improvements and performance optimizations
- Fork the repository
- Create a new branch for your contribution
- Make your changes, following the project's existing code style
- Add or update tests if applicable
- Ensure all existing tests pass
- Submit a pull request with a clear description of your changes
- Follow the existing code style in the project
- Use ESLint for code linting (configuration provided in
.eslintrc) - Write clear, concise commit messages
- Include comments for complex logic
- Ensure backward compatibility with React Native >=0.47.0
- Run existing tests before submitting a pull request
- Add tests for new functionality or bug fixes
- Verify your changes work across supported platforms
- Use GitHub Issues to report bugs or suggest features
- Provide a clear and detailed description
- Include steps to reproduce the issue
- If reporting a bug, include your environment details (React Native version, device, etc.)
This project is currently deprecated. While contributions are welcome, the maintainers recommend using Node.js Mobile for similar functionality.
By contributing, you agree that your contributions will be licensed under the project's MIT License.
This project is licensed under the MIT License.
The MIT License is a permissive free software license originating at the Massachusetts Institute of Technology. It puts limited restrictions on reuse and has, therefore, high license compatibility.
- Commercial use
- Modification
- Distribution
- Private use
- No Liability
- No Warranty
The full license text can be found in the LICENSE file in the project root. The license covers the entire project and applies to all code, documentation, and resources.
Copyright (c) 2017-present André Staltz (staltz.com)