How to set log level in Winston/Node.js

If you are using the default logger, you can adjust the log levels like this: const winston = require(‘winston’); // … winston.level=”debug”; will set the log level to ‘debug’. (Tested with winston 0.7.3, default logger is still around in 3.2.1). However, the documentation recommends creating a new logger with the appropriate log levels and then … Read more

Embed image in email body nodemailer nodejs

Responding here in case anyone else encounters this! The __dirname above was really helpful, but this is my code to actually see the image embedded in the email My img tag: <img src=”https://stackoverflow.com/questions/48449379/cid:logo”> My attachments snippet: attachments: [{ filename: ‘Logo.png’, path: __dirname +’/folder/Logo.png’, cid: ‘logo’ //my mistake was putting “cid:logo@cid” here! }]

URL Rewriting with ExpressJS

You could rewrite the URL before you get to the handler you want to use. app.use(function(req, res, next) { if (req.url === ‘/toto’) { req.url=”/heytoto”; } next(); }); app.get(‘/heytoto’, …); I’ve used a similar method to do URL rewrites with regular expressions.

req.session is undefined using express-session

Once you mount a router onto an Express app, any subsequently declared middleware on that app won’t get called for any requests that target the router. So if you have this: app.use(router) app.use(session(…)); The session middleware won’t get called for any requests that get handled by router (even if you declare the routes that the … Read more

Difference between req.url and req.originalUrl in Express.js version 4

From the Express.js documentation: req.url is not a native Express property, it is inherited from Node’s http module. This property is much like req.url; however, it retains the original request URL, allowing you to rewrite req.url freely for internal routing purposes. For example, the “mounting” feature of app.use() will rewrite req.url to strip the mount … Read more

NodeJS Express – separate routes on two ports

Based on Explosion Pills suggestion above, I modified the code in roughly this way: var express = require(‘express’); var things = []; var app = express(); var admin_app = express(); var port = 8080; var admin_port = 8081; app.post(‘/factory/’, function(req, res) { //Create a thing and add it to the thing array }); //Assume more … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)