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

node-a2conf

v0.2.0

Published

node-a2conf is a JavaScript module which provides an easy way to configure apache2.

Downloads

15

Readme

node-a2conf

node-a2conf is a JavaScript module which provides an easy way to configure apache2.

npm package version number License

Development

Install dependencies

Install dependencies with npm:

npm i

Test

Test the code with Jest framework:

npm run test

Note: This package uses husky, pinst and commitlint to automatically execute test and lint commit message before every commit.

Build

Build production (distribution) files in the dist folder:

npm run build

It generates CommonJS (in dist/cjs folder), ES Modules (in dist/esm folder), as well as TypeScript declaration files (in dist/types folder).

Examples

Read and parse from a configuration file

const { fromFile } = require('node-a2conf');

const root = await fromFile('example.conf');

for (const vhost of root.children('VirtualHost')) {
  console.log(vhost.first('ServerName'));
}

Read and parse from a text string

const { fromText } = require('node-a2conf');

const root = await fromText(`<VirtualHost *:80>
  ServerAdmin [email protected]
  ServerName example.com
  ServerAlias www.example.com example.example.com
  ServerAlias x.example.com
  DocumentRoot /usr/local/apache/htdocs/example.com
  SSLEngine On
</VirtualHost>`);

root.findVHost('example.com')?.set('SSLEngine', 'Off')

console.log(root.dump());

Create a new configuration

const { Node } = require('node-a2conf');

const root = new Node();
const vhost = root.insert('<VirtualHost *:80>');
vhost.insert('ServerName example.net');
vhost.insert('DocumentRoot /var/www/examplenet/');
vhost.insert('ServerAlias www.example.net', 'servername');

console.log(root.dump());
/*
<VirtualHost *:80>
    ServerName example.net
    ServerAlias www.example.net
    DocumentRoot /var/www/examplenet/
</VirtualHost>
*/

API

Node

isOpen()

Returns true if this node opens section, e.g <VirtualHost> or <IfModule>.

isClose()

Returns true if this node closes section.

add(child: Node)

Append child to node.

addRaw(raw: string)

Append string as child to node.

insert(childNode: Node | string, afterNode?: Node | string)

Insert child after another node.

set(name: string, value: string)

Set the value of a property given its name. If multiple properties with the same name are in the node, they will all be replaced.

getOpenTag()

Returns the open tag, e.g <VirtualHost>.

getCloseTag()

Returns the open tag, e.g </VirtualHost>.

filter(pattern: RegExp | string)

Returns children matching a pattern.

children(name?: string, { recursive } = { recursive: false })

Returns children matching name. Set recursive to true to search for nested nodes as well.

first(name: string, { recursive } = { recursive: false })

Returns the first child matching a name. Set recursive to true to search for nested nodes as well.

extend(n: Node)

Extends a node with another node.

readText(text: string)

Parses raw text and replace all content from that node with the newly parsed content.

readFile(fileName: string)

Parses a file and replace all content from that node with the newly parsed content.

writeFile(fileName: string)

Dumps the content of a node as a string into a file.

dump(depth = 0)

Dumps the content of a node as a string. Set depth to the base number of spaces to append on each line.

toString()

Returns the node name as a string.

delete()

Deletes the node from its parent.

findVHost(hostname: string, arg?: string)

Helper function to find a VHost given its name and optional arguments. Returns a Node or null if no VHost matches the parameters.

fromText(text: string, props?: NodeProps)

Reads and parses a file then returns a Node object.

fromFile(fileName: string, props?: NodeProps)

Parses a raw text string then returns a Node object.

References

  • https://github.com/yaroslaff/a2conf/