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

express-static-files-manager

v0.0.11

Published

An express static files manager

Downloads

7

Readme

npm (scoped)

express-static-files-manager

This package automatically builds and updates your static served files on express based on a given Github repository.

Installation

npm i express-static-files-manager

If you use TypeScript, make sure it's the latest version.

Motivations

On some of our projects, we use a pattern that allows us to have a single hosting point. We use express static files to serve the frontend directly from our backend (in this case an express app). The motivation behind this package comes from the need we had to automatically update the files served by our backend and not manually copy our React project build each time into the public folder and then redeploying the updated backend. This package also takes care of automatically updating the served frontend based on its current repository state. If the webhook is set up it will clone, rebuild and update the served files all by itself upon new commits.

Usage

manageStaticFilesServing(config : Config)

The only function that needs to be called when your express app starts. This will clone your project, build it and then place it within your /public directory (or the custom public directory if that is set) ready to be served by your express webserver. For this package, the default location of the /public directory is at the root of your project. If you set up the webhook, this will also automatically update your served files within the /public directory upon new commits.

src/index.ts

import express from 'express';
import path from 'path';
import { manageStaticFilesServing } from 'express-static-files-manager';

const app = express();

app.use(express.static(path.join(__dirname, '../public')));

manageStaticFilesServing({
  repoUrl: 'https://github.com/Username/yourReponame',
  showConsoleLog: true
});

Config

| field | type | defaultValue | mandatory | description | | ----------------- | ------------- | ---------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------- | | repoUrl | string | undefined | yes | Your repository's URL | | onHookReceived | function | undefined | no | Overwrites default express-static-files-manager hook controller passing express res, req and next fields to your function | | onStartBuild | function | undefined | no | Function called on build start | | onError | function | undefined | no | Function called on error | | onFinish | function | undefined | no | Function called on build finish | | githubUsername | string | undefined | no | Your github username | | githubPassword | string | undefined | no | Your github password | | githubToken | string | undefined | no | Your github OAuth token | | allowStdio | boolean | false | no | Setting this to true will pipe to stdio | | showConsoleLog | boolean | false | no | Setting this to true will log the whole process | | skipNpmInstall | boolean | false | no | If you wish to skip npm install phase | | skipBuildPhase | boolean | false | no | If you wish to skip build phase | | branch | string | "master" | no | Your branch name | | customPublicDir | string | "public" | no | The directory containing your public static files | | customWorkDir | string | $currentDir | no | The directory where builds are generated and processed | | customBuildScript | string | "build" | no | Set a custom script to use in your packages.json to build your files | | webhookConfig | WebhookConfig | undefined | no | The Github webhook config |

WebhookConfig

| field | type | defaultValue | mandatory | description | | ---------- | -------- | ---------------- | ------------- | ---------------------------------------------------- | | expressApp | Express | undefined | yes | Your express app (const expressApp = express();) | | endpoint | string | undefined | yes | The endpoint called by your github hook | | secret | string | undefined | no | The secret passphrase associated to your github hook |

Webhook usage

  • Declare a webhook manually on your repository https://github.com/{yourOrganization}/{repostoryName}/settings/hooks/new
  • Assign it a route and express-static-files-manager will automatically take care of that endpoint as long as you set webhookConfig.endpoint accordingly.
  • Select "application/json" for the field "Content Type"
  • Create a secret passphrase and set webhookConfig.secret accordingly.

src/index.ts

import express from 'express';
import path from 'path';
import { manageStaticFilesServing } from 'express-static-files-manager';

const app = express();

app.use(express.static(path.join(__dirname, '../public')));

manageStaticFilesServing({
  repoUrl: 'https://github.com/yourUserName/yourRepositoryName',
  branch: 'production',
  webhookConfig: {
    endpoint: '/githubhook',
    secret: 'yoursupertopsecret',
    expressApp: app
  }
});

Github credentials

If your repository is private, make sure to either ideally set your SSH key on your hosting machine or alternately set githubUsername and githubPassword. You can also use a github access token for the githubToken. If you take this path, consider setting up a bot with limited access rights to your repository.

Disclaimer

This is still in early stage development. Not production ready. Use it at your own risks. This is also super project specific and very opinionated.