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

local-files

v2.0.3

Published

A local file server to allow webapps to access local directories and files

Downloads

3

Readme

local-files

An easy to use local file server that makes designated directories available for use with your webapps via a simple to use client API or CLI.

Motivation

I used to use Electron to create local graphics and (game) level editors. I realized that I didn't need much of what Electron provided. Mostly I needed to load and save files in local directories. I realized that a simple file server running in node could accomplish that.

There are other to achieve this in javascript through the browser, but none of the solutions are that great (at least currently). Similarly, you could accomplish this using Dropbox or Google Drive or similar services, but, again, it's not great if you want to work in a specific local directory without lots of scripting.

How it works

You run a simple node server script that calls the localFiles() to start the file server. The server runs local-files by importing it via import { localFilesServer } from 'local-files' and start it with localFiles(). This turns on the local-files server (which internally uses express) and provides client access to the local-files API and the designated directory (which defaults to '.').

In your client, you include import * as localFiles from 'local-files', and access the localFiles commands via, eg, const files = await localFiles.dir()`

Installation

npm install local-files

Complete Usage Example

You will need to clone this repository to see the full example. Here are the instructions:

  1. git clone https://github.com/davidfig/local-files.git
  2. cd local-files
  3. npm install
  4. npm run start
  5. open browser to http://localhost:8090/

See sample directory for a simple file listing and content loading.

Documentation

CLI

npm i -g local-files will install local-files globally, or install it locally and use node_modules/.bin/local-files

local-files --help presents the help

Usage: local-files <directory="."> <port=9988> <limit=100mb> will set up the server.

Either way, use the same client as below to access the hosted files.

Server

import { localFilesServer }from 'local-files'

/**

  • create a localFiles server
  • @param {LocalFileOptions} [userOptions]
  • @param {string} [userOptions.directory='.'] to serve files
  • @param {number} [userOptions.port=9988] to host localFiles server
  • @param {Function} [userOptions.log=console.log] log output (if null then uses console.log, if false turns off logging)
  • @param {Function} [userOptions.error=console.error] log error (if null then uses console.error, if false turns off error logging)
  • @param {string} [userOptions.limit="500mb"] limit for size of files served */ export function localFiles(userOptions: Partial = {}): Promise

Client

import * as localFiles from 'local-files'

export async function changePort(port: number) { _port = port }

/**

  • get a directory listing
  • @returns {string[]} */ export async function dir(): Promise<string[]>

/**

  • Downloads a javascript data structure from the server
  • @param {string} filename of json file
  • @returns {*} */ export async function loadJson(filename: string): Promise

/**

  • Uploads a javascript data structure to the server
  • @param {string} filename of json file
  • @param {*} data */ export async function saveJson(filename: string, data: any): Promise

/**

  • Checks whether file exists on server
  • @param {string} filename */ export async function exists(filename: boolean): Promise

/**

  • Deletes a file from the server
  • @param {string} filename */ export async function unlink(filename: string): Promise

/**

  • renames a file
  • @param {string} oldFilename
  • @param {string} newFilename */ export async function rename(oldFilename: string, newFilename: string): Promise

/**

  • returns fs.stat results for filename
  • @param {string} filename
  • @returns {Stats} */ export async function stat(filename: string): Promise

Client URL Posting

It's also possible to POST to the webserver to get files and information. See localFiles for the format (documentation TBD if requested).

License

MIT License (c) 2021 YOPEY YOPEY LLC by David Figatner (https://twitter.com/yopey_yopey)