node.jswinston

Can I use winston logging functions in my all ".js" file in my nodejs server?


I am creating a nodejs server. In this server I am going to use winston logging. This server is having some .js file related to webpages so do I need to use winston in all the .js files in place of console.log.


Solution

  • This server is haveing some .js file related to webpages

    If "having some .js file related to webpages" mean client-side JavaScript then you cannot use Winston on the client directly - what you could do is create a logging connection e.g. with WebSocket or Socket.io or even create a logging endpoint for your client-side code that would internally use Winston on the server side and use that for logging on the client side.

    If "having some .js file related to webpages" mean having multiple .js files on the backend then you can easily share a Winston instance with shared configuration and export it from a shared module that would be imported by all of the code that needs logging on the backend.