1.0.0 • Published 4 years ago

@jacobbubu/pidfile v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

@jacobbubu/pidfile

Build Status Coverage Status npm

A simple pidfile generate module (ref. https://github.com/kesla/pidlockfile)

Usage

import * as path from 'path'
import { promises as fs } from 'fs'
import pidlock from '@jacobbubu/pidfile'

const main = async () => {
  const filename = path.join(__dirname, 'lock.pid')
  const unlock = await pidlock(path.join(__dirname, 'lock.pid'), { unlockOnExit: false })
  if (unlock instanceof Error) {
    // unlock is an Error object withe message 'Lockfile already acquired'
  } else {
    const pid = await fs.readFile(filename, 'utf8')
    console.log({ pidInFile: pid, pid: process.pid })
    unlock()
  }
}

main()

Before push

Before pushing the code to GitHub, please make sure that NPM_TOKEN is configured in https://github.com/__your_repo__/settings/secrets, or you can do this through semantic-release-cli.