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

as-a

v2.2.7

Published

Runs a given command with additional environment settings for simple local development

Downloads

38,863

Readme

as-a

Runs a given command with additional environment settings for simple local development

NPM

ci status semantic-release

as-a = run "as a" ...

Install

npm install --global as-a

You can run this tool without installing it

npx as-a [section name] [command ...]

You can also install this tool locally as a dev dependency. In that case, it will start faster than using npx as-a ... without an install.

npm i -D as-a
npx as-a [section name] [command ...]

Use

Create a file in your user's home directory .as-a.ini

touch ~/.as-a.ini

Create separate sections for groups of environment settings. For example

; this is a test section
[test]
name=test
why=just because

Now you can run any command (with arguments) and add the section as environment variables.

$ npm run env | grep why
--- nothing ----
$ as-a test npm run env | grep why
why=just because

Recommended to keep private settings for DEV urls, secrets, etc.

Multiple profiles

You can even use settings from multiple groups of settings using comma-separated list

[DEV]
username=tester
password=pass1234
[redis]
REDIST_HOST=localhost:4534
as-a DEV,redis node index.js

Current folder

A good practice for me was naming a section after the folder name. For example, if the INI file has the following:

[my-server-repo]
DB_USERNAME=user1234

Then we can inject the variables by running in the folder "my-server-repo" using "."

/my/folders/my-server-repo: $ as-a . node ./start
# injects section "my-server-repo"

Use case

Read how to run a Redis server inside the Docker container using as-a in this gist.

Secret folder

To better separate secrets from user home folder, you can place the .as-a.ini file into subfolder ~/.as-a/.as-a.ini.

Local file

Sometimes it makes sense to have a local file .as-a.ini in the project's folder (current working directory) with settings that should override any section from the home folder's .as-a.ini. Just create such file and use it.

Tip: when using a local .as-a.ini file make sure to git ignore .as-a.ini to avoid accidentally committing this file to the repository.

Resolution

  • local .as-a.ini + ~/.as-a.ini => combination, local file wins
  • local .as-a.ini + ~/.as-a/.as-a.ini => combination, local file wins
  • local .as-a.ini => just this file
  • otherwise an error is thrown

Section aliases

Just like you can use multiple sections, the INI sections themselves can have multiple aliases. For example, you can have the same section under two or more names to avoid duplication:

; you can use these environment variables by using name "user" or "personal"
[user, personal]
NAME=...
ID=...

These two commands are equivalent

$ as-a user ...
$ as-a personal ...

Version

To see the version of the installed as-a run it without arguments

$ as-a
[email protected]
 > Runs a given command with additional environment settings
 > for simple local development
use    : as-a <env settings name> [command with options]
example: as-a DEV node client.js --request foo

NPM module API

getSettings

Loads the specified settings sections and returns merged object

const {getSettings} = require('as-a')
// load sections [db] and [app]
getSettings('db,app') // {DB_HOST:...,USERNAME:...}

Debugging

If the settings are not applied correctly, run the command with DEBUG=as-a variable

$ DEBUG=as-a as-a name command arguments ...
  as-a loading sections +1ms [ 'name' ]
  as-a running "npx" with extra env keys +0ms [ 'USERNAME', 'PASSWORD' ]
  ..

Read

Small print

Author: Gleb Bahmutov © 2016

License: MIT - do anything with the code, but don't blame me if it does not work.

Spread the word: tweet, star on github, etc.

Support: if you find any problems with this module, email / tweet / open issue on Github

MIT License

Copyright (c) 2016 Gleb Bahmutov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.