Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import Winston in an Express app.
Express
const winston = require('[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' instead of 'winston' in require.
Confusing with 'morgan' which is another logger.
✗ Incorrect
Winston is imported by requiring the 'winston' package.
2fill in blank
mediumComplete the code to create a Winston logger with console transport.
Express
const logger = winston.createLogger({ transports: [new winston.transports.[1]()] }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'File' transport without specifying filename.
Using 'Http' transport which sends logs over HTTP.
✗ Incorrect
The Console transport sends logs to the console (terminal).
3fill in blank
hardFix the error in the code to log an info message using Winston.
Express
logger.[1]('Server started successfully');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' which is not a Winston method.
Using 'write' which is not a method on logger.
✗ Incorrect
The 'info' method logs an informational message in Winston.
4fill in blank
hardFill both blanks to configure Winston to log errors to a file named 'error.log'.
Express
const logger = winston.createLogger({ transports: [new winston.transports.[1]({ filename: '[2]' })] }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Console transport with filename option (ignored).
Using wrong filename like 'combined.log' for error logs.
✗ Incorrect
The File transport writes logs to a file. Here, the file is 'error.log'.
5fill in blank
hardFill all three blanks to create a logger that logs info level to console and errors to 'error.log' file.
Express
const logger = winston.createLogger({ level: '[1]', transports: [new winston.transports.[2](), new winston.transports.[3]({ filename: 'error.log', level: 'error' })] }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting level to 'debug' which logs too much.
Using Console transport for file logging.
✗ Incorrect
The logger's default level is 'info'. Console transport logs info and above. File transport logs errors to 'error.log'.