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

etc-passwd

v0.1.1

Published

Interface to read a standard Unix passwd and group file-format

Downloads

2,766

Readme

passwd(4) and group(4)

Interface to read a standard Unix passwd and group file-format

Install

Install locally to use as a module

npm install etc-passwd

Usage

as a module

var passwd = require('etc-passwd');

Functions

passwd.getUsers([file])

Get all users found in file. This functions returns an instance of EventEmitter.

The optional parameter file defaults to /etc/passwd

.on('user', function(user) {})

Returns an object whenever a user is found

.on('end', function() {})

Called when the file is done being read

passwd.getUsers([file], callback(users))

If a callback is supplied as the last argument, the entire file will be read at once, and the results will be returned as a list of user objects. This is good for convenience, but can produce unnecessary overhead on systems with a lot of users.


passwd.getUser({'username':'root'}, [file], callback(err, user))

Look for a specific username in file (defaults to /etc/passwd). This will use the EventEmitter to avoid loading the entire file into memory and return the callback when the user is found. If the user is not found err will be set and user will be null. You can specify any attribute to look for as the first argument.


passwd.getGroups([file])

Get all groups found in file. This functions returns an instance of EventEmitter.

The optional parameter file defaults to /etc/group

.on('group', function(group) {})

Returns an object whenever a group is found

.on('end', function() {})

Called when the file is done being read

passwd.getGroups([file], callback(groups))

If a callback is supplied as the last argument, the entire file will be read at once, and the results will be returned as a list of group objects. This is good for convenience, but can produce unnecessary overhead on systems with a lot of groups.


passwd.getGroup({'groupname':'wheel'}, [file], callback(err, group))

Look for a specific groupname in file (defaults to /etc/group). This will use the EventEmitter to avoid loading the entire file into memory and return the callback when the group is found. If the group is not found err will be set and group will be null. You can specify any attribute to look for as the first argument.

Example

passwd.getUsers()

An example of using the EventEmitter interface to find users

var passwd = require('passwd'),
    users = passwd.getUsers();

users.on('user', function(user) {
  console.log(JSON.stringify(user));
});
users.on('end', function() {
  console.log('Done.');
});
{"username":"nobody","password":"*","uid":-2,"gid":-2,"comments":"Unprivileged User","home":"/var/empty","shell":"/usr/bin/false"}
{"username":"root","password":"*","uid":0,"gid":0,"comments":"System Administrator","home":"/var/root","shell":"/bin/sh"}
...
Done.

passwd.getUsers(callback(users))

Using the callback instead of the EventEmitter to get the results

var passwd = require('passwd');
passwd.getUsers(function(users) {
  console.log(JSON.stringify(users));
});
[
{"username":"nobody","password":"*","uid":-2,"gid":-2,"comments":"Unprivileged User","home":"/var/empty","shell":"/usr/bin/false"},
{"username":"root","password":"*","uid":0,"gid":0,"comments":"System Administrator","home":"/var/root","shell":"/bin/sh"},
...
]

passwd.getUser()

As for a specific user on the system

var passwd = require('etc-passwd');
passwd.getUser({'username':'root'}, function(err, user) {
  console.log(JSON.stringify(user));
});
{"username":"root","password":"*","uid":0,"gid":0,"comments":"System Administrator","home":"/var/root","shell":"/bin/sh"}

passwd.getGroups()

An example of using the EventEmitter interface to find groups

var passwd = require('passwd'),
    groups = passwd.getGroups();

groups.on('group', function(group) {
  console.log(JSON.stringify(group));
});
groups.on('end', function() {
  console.log('Done.');
});
{"groupname":"nobody","password":"*","gid":-2,"users":[]}
{"groupname":"nogroup","password":"*","gid":-1,"users":[]}
...
Done.

passwd.getGroups(callback(groups))

Using the callback instead of the EventEmitter to get the results

var passwd = require('passwd');
passwd.getGroups(function(groups) {
  console.log(JSON.stringify(groups));
});
[
{"groupname":"nobody","password":"*","gid":-2,"users":[]}
{"groupname":"nogroup","password":"*","gid":-1,"users":[]}
...
]

passwd.getGroup()

var passwd = require('etc-passwd');
passwd.getGroup({'groupname':'wheel'}, function(err, group) {
  console.log(JSON.stringify(group));
});
{"groupname":"wheel","password":"*","gid":0,"users":["root"]}

License

MIT Licensed