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

@jb_fmanager/node-utils

v1.1.0

Published

utlity package for jb file manager and nodejs backend

Downloads

2

Readme

npm i @jb_fmanager/node-utils

yarn add @jb_fmanager/node-utils

[get] map

Maps the provided path, returns a parent / child tree structure

const { map } = require("@jb_fmanager/node-utils");

app.get("/api/fm/map", async (request, response) => {
  try {
    // expects root folder argument, the directory in the filesystem that you want to map
    // result is the formatted file tree
    // throws error

    const result = await map(root);

    // response has to include result as json
  } catch (e) {
    console.error(e);
  }
});

[get] create_folder

Creates new directory in the specified path

const { create_folder } = require("@jb_fmanager/node-utils");

app.get("/api/fm/create_folder", async (request, response) => {
  try {
    // expects path and name arguments from the query
    // void
    // throws error

    await create_folder(request.query.path, request.query.name);

    // any response
  } catch (e) {
    console.error(e);
  }
});

[get] rename

Renames a file

const { rename } = require("@jb_fmanager/node-utils");

app.get("/api/fm/rename", async (request, response) => {
  try {
    // expects oldPath and newPath arguments from the query
    // void
    // throws error

    await rename(request.query.oldPath, request.query.newPath);

    // any response
  } catch (e) {
    console.error(e);
  }
});

[post] remove

Removes a number of files recursively

const { remove } = require("@jb_fmanager/node-utils");

app.post("/api/fm/remove", async (request, response) => {
  try {
    // expects the request body
    // void
    // throws error

    await remove(request.body);

    // any response
  } catch (e) {
    console.error(e);
  }
});

[post] copy

Copies a number of files from one path to another

const { copy } = require("@jb_fmanager/node-utils");

app.post("/api/fm/copy", async (request, response) => {
  try {
    // expects target argument from query and request body
    // void
    // throws error

    await copy(request.query.target, request.body);

    // any response
  } catch (e) {
    console.error(e);
  }
});

[post] move

Moves a number of files from one path to another

const { move } = require("@jb_fmanager/node-utils");

app.post("/api/fm/move", async (request, response) => {
  try {
    // expects target argument from query and request body
    // void
    // throws error

    await move(request.query.target, request.body);

    // any response
  } catch (e) {
    console.error(e);
  }
});

[post] upload

Saves a number of files into the given destination

const { upload } = require("@jb_fmanager/node-utils");

app.post("/api/fm/upload", async (request, response) => {
  try {
    // expects request, response, destination and max_size (optional) arguments
    // result is an object with two array properties, one containing succesful and the other containing failed uploads
    // throws error

    const result = await upload(
      request,
      response,
      request.query.destination,
      request.query.max_size
    );

    // response should include the result in json
  } catch (e) {
    console.error(e);
  }
});
// Next.js - blocking default parser on "api/fm/upload" route example

export const config = {
  api: {
    bodyParser: false,
  },
};

// process upload
// fastify - adding a custom multipart/form-data parser which will pass the request onwards

const fastify = require("fastify")({});

fastify.addContentTypeParser(
  "multipart/form-data",
  function (request, payload, done) {
    done(null, payload);
  }
);

// then inside your route

upload(request.raw, response.raw, ...)

// in fastify the instance of IncomingMessage can be found under request.raw,