Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-fs

Package Overview
Dependencies
Maintainers
2
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-fs

Native filesystem access for react-native

  • 2.0.1-rc.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is react-native-fs?

react-native-fs is a library for file system access in React Native. It provides a wide range of functionalities for reading, writing, and managing files and directories on both iOS and Android platforms.

What are react-native-fs's main functionalities?

Read a File

This feature allows you to read the contents of a file. The code sample reads a file named 'test.txt' from the document directory and logs its contents.

const RNFS = require('react-native-fs');

RNFS.readFile(RNFS.DocumentDirectoryPath + '/test.txt', 'utf8')
  .then((contents) => {
    console.log(contents);
  })
  .catch((err) => {
    console.log(err.message, err.code);
  });

Write a File

This feature allows you to write data to a file. The code sample writes 'Lorem ipsum dolor sit amet' to a file named 'test.txt' in the document directory.

const RNFS = require('react-native-fs');

const path = RNFS.DocumentDirectoryPath + '/test.txt';

RNFS.writeFile(path, 'Lorem ipsum dolor sit amet', 'utf8')
  .then(() => {
    console.log('FILE WRITTEN!');
  })
  .catch((err) => {
    console.log(err.message);
  });

Delete a File

This feature allows you to delete a file. The code sample deletes a file named 'test.txt' from the document directory.

const RNFS = require('react-native-fs');

const path = RNFS.DocumentDirectoryPath + '/test.txt';

RNFS.unlink(path)
  .then(() => {
    console.log('FILE DELETED');
  })
  .catch((err) => {
    console.log(err.message);
  });

Download a File

This feature allows you to download a file from a remote URL. The code sample downloads a file from 'https://example.com/test.txt' and saves it to the document directory.

const RNFS = require('react-native-fs');

const url = 'https://example.com/test.txt';
const path = RNFS.DocumentDirectoryPath + '/test.txt';

RNFS.downloadFile({ fromUrl: url, toFile: path }).promise
  .then((result) => {
    console.log('FILE DOWNLOADED', result);
  })
  .catch((err) => {
    console.log(err.message);
  });

List Files in a Directory

This feature allows you to list all files in a directory. The code sample lists all files in the document directory.

const RNFS = require('react-native-fs');

RNFS.readDir(RNFS.DocumentDirectoryPath)
  .then((result) => {
    console.log('GOT RESULT', result);
  })
  .catch((err) => {
    console.log(err.message, err.code);
  });

Other packages similar to react-native-fs

Keywords

FAQs

Package last updated on 10 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc