Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ ONeal committed Feb 11, 2011
0 parents commit 3f029c3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
@@ -0,0 +1,16 @@
pid
===

Install

npm install pid

Usage

var pider = require('pid');

pider('node-pid'); // /tmp/node-pid.pid -- puts in /tmp with ext .pid by default

pider('./node-pid'); // ./node-pid

pider('/var/run/node-pid.pid'); // /var/run/node-pid.pid -- if you have permissions
16 changes: 16 additions & 0 deletions example/pid-test.js
@@ -0,0 +1,16 @@
(function () {
"use strict";

var exec = require('child_process').exec,
pider = require('pid');

pider('node-pid-test');
pider('./node-pid-test2');
pider('./node-pid-test3.pid');
pider('node-pid-test4.pid');
setTimeout(function () {
exec("ls ./ /tmp | grep node", function (err, stdout, stderr) {
console.log(stdout);
});
}, 100);
}());
20 changes: 20 additions & 0 deletions lib/pid.js
@@ -0,0 +1,20 @@
(function () {
"use strict";

var fs = require('fs');

module.exports = function (path) {
if (!/\//.test(path)) {
if (!/\.pid/.test(path)) {
path += '.pid';
}
path = '/tmp/' + path;
}

fs.writeFile(path, process.pid.toString() + '\n');
process.on('exit', function () {
fs.unlink(path);
});
};

}());
12 changes: 12 additions & 0 deletions package.json
@@ -0,0 +1,12 @@
{
"name" : "pid",
"description" : "Creates a pid file.",
"url" : "http://github.com/coolaj86/node-pid/",
"keywords" : ["util", "pid"],
"author" : "AJ ONeal <coolaj86@gmail.com>",
"contributors" : [],
"dependencies" : [],
"lib" : "lib",
"main" : "./lib/pid",
"version" : "1.0.0"
}

0 comments on commit 3f029c3

Please sign in to comment.