Usage:
- npm i
- npm run buld
- npm run start
SETUP a new TSUP-NODE project:
-
mkdir donutStore && cd donutStore && npm init -y
-
npm i tsup typescript @xstate/store
-
mkdir src && touch src/index.tsx
Pasted in code into src/index.tsx
-
Update package.json added the follow:
"type": "module"
"scripts": {
"build": "tsup-node src/index.tsx --format esm --dts",
"start": "node dist/index.js",
"tsc": "tsc --noEmit"
},
- npm run tsc -- --init
- npm run build
- npm run start
Add PINO Log Aggregator to project:
- npm i pino pino-pretty
- Setup a src/logger.ts file:
import pino from 'pino';
// Configure Pino logger with info level and pretty printing
const logger = pino({
level: 'info',
transport: {
target: 'pino-pretty',
options: {
colorize: true,
translateTime: 'SYS:standard',
ignore: 'pid,hostname',
},
},
});
export default logger;
NOTE: Each logging method has the following signature: ([mergingObject], [message], [...interpolationValues])
The message string may contain a printf style string with support for the following placeholders:
%s – string placeholder
%d – digit placeholder
%O, %o and %j – object placeholder
Example:
logger.info('%o hello %s', {worldly: 1}, 'world')
// {"level":30,"time":1531257826880,"msg":"{"worldly":1} hello world","pid":55956,"hostname":"x"}