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

htpasswd-mgr

v2.0.3

Published

HTPasswd Manager for Node.js

Downloads

57

Readme

htpasswd-mgr - The HTPasswd Manager for Node

NPM version Downloads Minzipped Size Build Status Coverage Status Typings

This module was developed to simplify the management of .htpasswd files from a Node.js application. Specifically, it's intended to allow for the addition, modification, and deletion of users programmatically from inside a Node application.

Usage

let manager = require('htpasswd-mgr'),
    htpasswdManager = manager('./.htpasswd');
    
// Add a user with username 'john' and password 'password123' via the 'crypt' algorithm
htpasswdManager.addUser('john', 'password123', { algorithm: 'crypt', export: false });

Intializing

First, the module must be initialized with a String path to an htpasswd file. Once initialized, a set of functions will be returned which allow for the manipulation of the data in that file. Those functions will be covered in the following sections.

Note: A single instance of the htpasswd-mgr can be used to manage multiple htpasswd files.

updateState

htpasswdManager.updateState()

This function updates the internal state of the module to be consistent with the current file as it exists on the file system. This exists as a hook for programmatically allowing the module to remain up-to-date if changes are made directly to the underlying htpasswd file. Ideally, this function should not need to be called.

Returns: Promise<void>

htpasswdManager.updateState()
    .then(() => { ... })
    .catch((err) => { ... });

updateFile

htpasswdManager.updateFile()

This function updates the htpasswd file on the file system to be consistent with the current state of the module. This is provided in case a number of updates will be made to the htpasswd file so that each addUser call does not need to write the file to the disk. Instead, with this function, one could add several users to the htpasswd file and then manually call this function to write the file out to disk.

Returns: Promise<void>

htpasswdManager.updateFile()
    .then(() => { ... })
    .catch((err) => { ... });

addUser

htpasswdManager.addUser(username, password, options)

This function adds a user to the htpasswd file. It is not intended to update user accounts. Attempting to update an account with this function will result in a rejected Promise.

  • username - String - The username of the user to be added.
  • password - String - The password of the user to be added.
  • options - Object - An object specifying the specific functionality.
    • options.algorithm - String - 'crypt', 'bcrypt', 'sha', or 'md5'. Default: 'md5'
    • options.export - Boolean - Should the module state be exported to the htpasswd file? Default: true

Returns: Promise<void>

htpasswdManager.addUser(username, password, options)
    .then(() => { ... })
    .catch((err) => { ... });

updateUser

htpasswdManager.updateUser(username, password, options)

This function updates a user to the htpasswd file. It is not intended to add user accounts. Attempting to add an account with this function will result in a rejected Promise.

  • username - String - The username of the user to be updated.
  • password - String - The password of the user to be updated.
  • options - Object - An object specifying the specific functionality.
    • options.algorithm - String - 'crypt', 'bcrypt', 'sha', or 'md5'. Default: 'md5'
    • options.export - Boolean - Should the module state be exported to the htpasswd file? Default: true

Returns: Promise<void>

htpasswdManager.updateUser(username, password, options)
    .then(() => { ... })
    .catch((err) => { ... });

upsertUser

htpasswdManager.upsertUser(username, password, options)

This function allows for an account with the provided username to be added or updated without worrying about a rejected Promise if the user account already exists (in the case of adding a new user), or if the account does not exist (in the case of updating a user). This provides a means of overriding any existing account and updating it with the provided values.

  • username - String - The username of the user to be upserted.
  • password - String - The password of the user to be upserted.
  • options - Object - An object specifying the specific functionality.
    • options.algorithm - String - 'crypt', 'bcrypt', 'sha', or 'md5'. Default: 'md5'
    • options.export - Boolean - Should the module state be exported to the htpasswd file? Default: true

Returns: Promise<void>

htpasswdManager.upsertUser(username, password, options)
    .then(() => { ... })
    .catch((err) => { ... });

removeUser

htpasswdManager.removeUser(username, options)

This function removes a user from the htpasswd file.

  • username - String - The username of the user to be updated.
  • options - Object - An object specifying the specific functionality.
    • options.export - Boolean - Should the module state be exported to the htpasswd file? Default: true

Returns: Promise<void>

htpasswdManager.addUser(username, options)
    .then(() => { ... })
    .catch((err) => { ... });

listUsers

htpasswdManager.listUsers()

This function will return an array of the users currently in the htpasswd file.

Returns: Promise<string[]>

htpasswdManager.listUsers()
    .then((users) => { console.log('Users', users); });

Tests

$ npm test

To see test coverage, please run:

$ npm run coverage