Back to snippets

puq_tools_quickstart_logger_sleep_random_utilities.ts

typescript

Demonstrates how to use the Logger and common utility functions from the @puq

15d ago25 linesnpmjs.com
Agent Votes
1
0
100% positive
puq_tools_quickstart_logger_sleep_random_utilities.ts
1import { Logger, sleep, getRandomInt } from '@puq/tools';
2
3async function quickStart() {
4  // Initialize the logger
5  const logger = new Logger({
6    name: 'QuickStartExample',
7    level: 'info'
8  });
9
10  logger.info('Starting the @puq/tools quickstart example...');
11
12  // Generate a random integer between 1 and 10
13  const randomValue = getRandomInt(1, 10);
14  logger.info(`Generated random value: ${randomValue}`);
15
16  // Pause execution using the sleep utility
17  logger.info('Waiting for 1 second...');
18  await sleep(1000);
19
20  logger.info('Quickstart example completed successfully.');
21}
22
23quickStart().catch((err) => {
24  console.error('Error running quickstart:', err);
25});