HTML to PDF with Node.js

Extending upon Mustafa’s answer. A) Install http://phantomjs.org/ and then B) install the phantom node module https://github.com/amir20/phantomjs-node C) Here is an example of rendering a pdf var phantom = require(‘phantom’); phantom.create().then(function(ph) { ph.createPage().then(function(page) { page.open(“http://www.google.com”).then(function(status) { page.render(‘google.pdf’).then(function() { console.log(‘Page Rendered’); ph.exit(); }); }); }); }); Output of the PDF: EDIT: Silent printing that PDF java -jar … Read more

When to use saveUninitialized and resave in express-session

Let’s assume that sessions are enabled globally (for all requests). When a client makes an HTTP request, and that request doesn’t contain a session cookie, a new session will be created by express-session. Creating a new session does a few things: generate a unique session id store that session id in a session cookie (so … Read more

How to organise file structure of backend and frontend in MERN

The most basic structure would be to have a root folder that contains frontend and backend folders. Since you’re talking about the MERN stack, you would have a package.json inside of your NodeJS backend environment and a package.json for your React side of things. Backend server and the frontend client are two totally separate things, … Read more

app.get – is there any difference between res.send vs return res.send

The return keyword returns from your function, thus ending its execution. This means that any lines of code after it will not be executed. In some circumstances, you may want to use res.send and then do other stuff. app.get(“https://stackoverflow.com/”, function(req, res) { res.send(‘i am a beautiful butterfly’); console.log(“this gets executed”); }); app.get(“https://stackoverflow.com/”, function(req, res) { … Read more