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 🙏

© 2024 – Pkg Stats / Ryan Hefner

expo-static-server

v0.2.5

Published

A static server for expo

Downloads

32

Readme

expo-static-server

A static server for expo.

This library supports both Android and IOS right now.

Install

npx expo install expo-static-server
# or
npm i expo-static-server
# or
yarn add expo-static-server

Usage

import * as FileSystem from "expo-file-system";
import { stopServer, startServer } from "expo-static-server";
import React, { useEffect } from "react";

export function TestComponent(props: { children: React.ReactNode }) {
  useEffect(() => {
    // Start server
    startServer({
      port: 8080,
      host: "127.0.0.1",
      root: FileSystem.documentDirectory || "",
    })
      .then(() => {
        console.log(`The static server is running`);
      })
      .catch(console.error);

    return () => {
      // Stop server
      stopServer()
        .then(() => {
          console.log(`The static server is stoped`);
        })
        .catch(console.error);
    };
  }, []);
  return <>{props.children}</>;
}

API

startServer

Starts a static server and serves files from the specified root directory.

type startServer = (props: {
  host: string,
  port: number,
  root: string,
}) => Promise<void>

Example:

Starts a static server and serves the specified files.

import * as FileSystem from "expo-file-system";
import { startServer } from "expo-static-server";

export async function startFileServerByFiles(props: {
  port: number;
  host: string;
  files: { uri: string; name: string; type: string }[];
}) {
  const { port, host, files } = props;
  const root =
    (FileSystem.documentDirectory || "") + "expo_static_server_root_files";
  for (const file of files) {
    const fileName = `${file.name}${file.type ? "." + file.type : ""}`;
    await FileSystem.copyAsync({
      from: file.uri,
      to: root + "/" + fileName,
    });
  }
  await startServer({
    port,
    host,
    root,
  });
}

Starts a static server and serves files extracted from the specified zip file.

import * as FileSystem from "expo-file-system";
import { startServer } from "expo-static-server";
import { unzip } from 'react-native-zip-archive';

export async function startFileServerByZipFileUri(props: {
  port: number;
  host: string;
  zipFileUri: string;
}) {
  const { port, host, zipFileUri } = props;
  const root =
    (FileSystem.documentDirectory || "") + "expo_static_server_root_zip_files";
  await unzip(zipFileUri, root);
  await startServer({
    port,
    host,
    root,
  });
}

stopServer

Stop the static server.

type stopServer = () => Promise<void>

Permissions

If you want to access external storage in your project, you may need to add the following permissions:

  • Android: READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE