index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const binding = require('./binding')
  2. const errors = require('./lib/errors')
  3. const constants = require('./lib/constants')
  4. exports.constants = constants
  5. exports.EOL = binding.platform === 'win32' ? '\r\n' : '\n'
  6. exports.platform = function platform () {
  7. return binding.platform
  8. }
  9. exports.arch = function arch () {
  10. return binding.arch
  11. }
  12. exports.type = binding.type
  13. exports.version = binding.version
  14. exports.release = binding.release
  15. exports.machine = binding.machine
  16. exports.execPath = binding.execPath
  17. exports.pid = binding.pid
  18. exports.ppid = binding.ppid
  19. exports.cwd = binding.cwd
  20. exports.chdir = binding.chdir
  21. exports.tmpdir = binding.tmpdir
  22. exports.homedir = binding.homedir
  23. exports.getEnvKeys = binding.getEnvKeys
  24. exports.getEnv = binding.getEnv
  25. exports.hasEnv = binding.hasEnv
  26. exports.setEnv = binding.setEnv
  27. exports.unsetEnv = binding.unsetEnv
  28. exports.kill = function kill (pid, signal = constants.signals.SIGTERM) {
  29. if (typeof signal === 'string') {
  30. if (signal in constants.signals === false) {
  31. throw errors.UNKNOWN_SIGNAL('Unknown signal: ' + signal)
  32. }
  33. signal = constants.signals[signal]
  34. }
  35. binding.kill(pid, signal)
  36. }
  37. exports.getProcessTitle = binding.getProcessTitle
  38. exports.setProcessTitle = function setProcessTitle (title) {
  39. if (typeof title !== 'string') title = title.toString()
  40. if (title.length >= 256) {
  41. throw errors.TITLE_OVERFLOW('Process title is too long')
  42. }
  43. binding.setProcessTitle(title)
  44. }