1.1.2 • Published 2 years ago
@neuledge/process v1.1.2
Process utilities
This package contains constants and helper functions that are useful in a Node.js process.
Install
Install the package:
yarn add @neuledge/processUsage
Running a service
Using runService automatically handles signals and logs errors so the service
can shutdown gracefully.
Running an HTTP service
import { runService } from '@neuledge/process';
import http from 'http';
const app = http.createServer((req, res) => {
  res.end('Hello World!');
});
runService({
  name: 'my-service',
  server: app,
  port: 3000,
  keepAliveSeconds: 30,
});Running a worker
import { printLog, runService, RunConfigProcess } from '@neuledge/process';
const worker = async (): Promise<RunConfigProcess> => {
  const interval = setInterval(() => {
    printLog('worker is running', 'info');
  }, 1000);
  const stop = async () => {
    clearInterval(interval);
  };
  return { name: 'watch', abort: stop };
};
runService(worker);Logging
import { Logger, ValidationPipe } from '@nestjs/common';
import { setLogger, printLog, printError } from '@neuledge/process';
// Set the logger to use the NestJS logger
setLogger(new Logger());
// Use the logger
printLog('Hello World!', 'info', { foo: 'bar' });
// Use the logger to print an error
printError('we got an error', new Error('Something went wrong!'), 'warn', {
  foo: 'bar',
});Environment variables
import { APP_ENV } from '@neuledge/process';
if (IS_LOCAL) {
  // Do something
} else if (APP_ENV === 'prod') {
  // Do something else
}1.1.2
2 years ago
1.1.1
2 years ago
1.1.0
2 years ago
1.0.0
2 years ago
1.0.0-alpha.19
2 years ago
1.0.0-alpha.18
2 years ago