NodeOS/node-npkg — pull request #1 by groundwater (2014-02-20 06:48:11+00:00)
Title: Experiments-1

Just messing around, trying to improve `npkg`. It's a bit of a mess, but here are my lessons learned.

### common api

We should think about a common dependency between `npkg` and `init` to keep the API in sync, i'm not sure if a module like this exists yet. Ideally I would define a set of remote-methods in a single file, and could load both the server and client side from that definition.

### config

Services generally require some environmental dependencies. For example, a webapp may need to connect to a leveldb, or mysql back end. The most common way to handle this is with environment variables, which I absolutely agree with. I don't want init to be any more intelligent than it needs to be, so I'm leaving it up to `npkg` to generate environment variables each service.

There are certain environment variables I want to pass in to *every* service:

- `VARDIR` should be a persistent directory, but unique for every service.
- `TMPDIR/TEMPDIR` should be persistent during the lifetime of a process, but is ephemeral across reboots.
- `ROOT` should be the location of the module
- `PATH` should be `$ROOT/node_modules/.bin:/bin` to include `node` and any executables listed in the services `package.json`.
- `HOME` is just the users home directory
- `USER` is the user name executing the service

Right now, the default values for each of the above are

```text
HOME=%{home}
USER=%{user}
VARDIR=%{home}/var/%{package}
TEMPDIR=%{tmpdir}/%{user}/%{package}
LOGDIR=%{home}/log/%{package}
ROOT=%{home}/lib/node_modules/%{package}
PATH=%{root}/node_modules/.bin=%{path}
```
I actually do something *clever* (for some definition of clever) right now, but I think it's doing too much.
For each service, I interpolate the above set of environment variables, filling in `tempdir, home, package, path` etc. I also let you override values for specific services, or add your own variables that can be interpolated.

It's too much, but we do need to support setting configs in some way.

So, I think I'm just going to read `$HOME/etc/npkg/$service.json` for the *exact* set of environment variables to be passed in. I'm still working through this idea.

ping @EndangeredMassa