{"id":17278,"library":"jsnlog","title":"JSNLog.js","description":"JSNLog.js is a compact (2kb min+gz) JavaScript logging library, currently at version 2.30.0, designed for both client-side and Node.js server-side environments. Its primary utility lies in enabling client-side log messages (such as exceptions or AJAX timeouts) to be sent and stored in existing server-side logging infrastructures, including .Net (supporting Log4net, Nlog, Elmah), PHP, and Node.js (via Winston transports). The library is notable for its extensive configuration options, allowing developers to precisely control and filter log data to minimize network traffic and storage, ensuring only relevant information is processed. Despite its utility and robust feature set, the project has been in maintenance mode for approximately five years, with no new releases or significant commits during that period, indicating an inactive development status, though it continues to be downloaded and used in existing projects. It ships with TypeScript type definitions, facilitating its use in modern TypeScript-based applications.","status":"maintenance","version":"2.30.0","language":"javascript","source_language":"en","source_url":"https://github.com/mperdeck/jsnlog.js","tags":["javascript","logging","client","exceptions","ajax","timeouts","debugging","winston","typescript"],"install":[{"cmd":"npm install jsnlog","lang":"bash","label":"npm"},{"cmd":"yarn add jsnlog","lang":"bash","label":"yarn"},{"cmd":"pnpm add jsnlog","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for Node.js server-side integration to handle and store client-side logs using Winston transports.","package":"winston","optional":true}],"imports":[{"note":"JSNLog exports 'JL' as a named export. Attempting a default import will result in a runtime error. This applies to consuming JSNLog in an ESM context.","wrong":"import JL from 'jsnlog';","symbol":"JL","correct":"import { JL } from 'jsnlog';"},{"note":"For CommonJS environments, the main JL logger instance is available as a property of the module export.","wrong":"const JSNLog = require('jsnlog'); JSNLog.JL().debug('message');","symbol":"JL (CommonJS)","correct":"const JL = require('jsnlog').JL;"},{"note":"When JSNLog is included directly via a script tag in HTML, it exposes the 'JL' object globally. This is common for client-side usage without a module bundler.","symbol":"JL (Global)","correct":"// With <script> tag inclusion: <script src=\"path/to/jsnlog.min.js\"></script>\nJL().debug('message from global JL');"}],"quickstart":{"code":"import { JL } from 'jsnlog';\nimport express from 'express';\nimport winston from 'winston';\nimport { JSNLogMiddleware } from 'jsnlog-nodejs'; // Assuming jsnlog-nodejs is installed for server-side\n\n// --- Client-side (in your frontend application) ---\n// Configure JSNLog to send logs to the /jsnlog endpoint on your server\nJL.setOptions({\n    \"appenders\": [\n        {\n            \"name\": \"ajaxAppender\",\n            \"type\": \"ajax\",\n            \"url\": \"/jsnlog\",\n            \"level\": \"DEBUG\", // Send all debug+ messages\n            \"bufferSize\": 1,\n            \"batchSize\": 5,\n            \"batchTimeout\": 1000\n        }\n    ],\n    \"defaultLogger\": {\n        \"appenders\": [\"ajaxAppender\"]\n    }\n});\n\nconsole.log('Client-side JSNLog configured. Sending logs to /jsnlog.');\n\n// Example client-side logging\nJL().debug('This is a debug message from the client');\nJL().info('An informational message from the client');\ntry {\n    throw new Error('Something went wrong on the client!');\n} catch (e: any) {\n    JL().fatalException('Caught a client-side error!', e);\n}\n\n// --- Server-side (in your Node.js application) ---\nconst app = express();\nconst PORT = process.env.PORT || 3000;\n\n// Configure Winston logger for server-side logging\nconst serverLogger = winston.createLogger({\n  level: 'info',\n  format: winston.format.json(),\n  transports: [\n    new winston.transports.Console(),\n    new winston.transports.File({ filename: 'combined.log' }),\n  ],\n});\n\n// Integrate JSNLog with Express and Winston\napp.use(JSNLogMiddleware(serverLogger));\n\napp.get('/', (req, res) => {\n  res.send('JSNLog example running. Check your client console and server logs!');\n});\n\napp.listen(PORT, () => {\n  console.log(`Server listening on port ${PORT}`);\n  console.log('Open your browser to http://localhost:3000 and check the network tab/console for client logs being sent.');\n  serverLogger.info('Server started and JSNLog middleware active.');\n});\n\n// To run this example:\n// 1. npm install jsnlog express winston jsnlog-nodejs\n// 2. Add \"type\": \"module\" to your package.json for ESM support if not already present.\n// 3. run `npx ts-node your-file.ts` (if using ts-node) or compile and run.","lang":"typescript","description":"This quickstart demonstrates setting up JSNLog for client-side logging, configuring it to send logs to a Node.js server, and integrating with a Winston logger on the server to process and store these client-side messages."},"warnings":[{"fix":"Be aware that community support may be limited and consider the long-term implications for new projects. Review the codebase for any potential unaddressed security concerns if integrating into critical systems.","message":"JSNLog has been in an inactive maintenance state for approximately five years, with no new releases or significant commits. While stable, active development and new features are not expected.","severity":"gotcha","affected_versions":">=2.30.0"},{"fix":"Always use a named import for `JL`: `import { JL } from 'jsnlog';`.","message":"When using ES Modules (ESM), importing JSNLog with a default import (e.g., `import JL from 'jsnlog';`) will result in a runtime `TypeError: jsnlog_1.JL is not a function`.","severity":"breaking","affected_versions":"All versions supporting ESM (likely >=v2)"},{"fix":"Refer to the JSNLog documentation (jsnlog.com / nodejs.jsnlog.com) for instructions on setting up the appropriate server-side handler for your backend technology.","message":"Effective client-side logging to a server requires a corresponding server-side handler (e.g., for Node.js, .Net, or PHP). The `jsnlog` npm package only provides the client-side library; server-side integration components (like `jsnlog-nodejs` for Winston) must be separately installed and configured.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change the import statement to a named import: `import { JL } from 'jsnlog';`.","cause":"Attempting to use `JL()` after importing JSNLog as a default ES module import (e.g., `import JL from 'jsnlog';`).","error":"TypeError: jsnlog_1.JL is not a function"},{"fix":"Ensure JSNLog is either imported using `import { JL } from 'jsnlog';` in a module environment or that `jsnlog.min.js` is included via a `<script>` tag before any code that calls `JL()` in a global script environment.","cause":"The JSNLog library was not loaded or imported correctly in the current scope, or the script tag for client-side usage was placed after code attempting to use `JL`.","error":"JL is not defined"},{"fix":"Verify that `jsnlog-nodejs` (or equivalent server-side package) is installed, its middleware is applied to your Express/Koa app, and it's correctly configured to use your Winston logger. Also, confirm the `url` in `JL.setOptions` matches your server's JSNLog endpoint.","cause":"The server-side JSNLog handler (e.g., `jsnlog-nodejs`) is not correctly installed, configured, or integrated with your server's logging framework (e.g., Winston), or the client-side `url` option for the AjaxAppender is incorrect.","error":"Client-side logs are not appearing in server logs (e.g., Winston files)"}],"ecosystem":"npm","meta_description":null}