Your Choice JavaScript News

Node News Tuesday, March 27 Youtube video, Boilerplate code, Boolean flags & more…

Node News TLDR / Table of Contents

  • Sending Emails using Sendgrid with Node.js – Keith Weaver –
    • I’m gonna cover sending basic HTML emails using Sendgrid with Node.js in this posting. If you are interested in seeing it done in Node.js, I’ve created a Youtube video. If you are interested in doing…
    • Youtube video, boilerplate code, MERN boilerplate code, function, Medium post
  • Misadventures in Node.js log rotation
    • Single thread doesn’t mean there are no race conditions
    • boolean flags, in-memory buffer, I/O operations, actual explicit sequencing, event loop
  • Making the Switch from Node.js to Golang Tutorial | Codeship
    • Making the switch from Node.js to Golang was the right decision for Alexandra Grant. Learn about her transition and how it has benefited her team.
    • Node, Octo, Node Octo, troublesome Node service, new Octo service
  • Lastly, you need to install all other Node modules so run: – npm installAfter that is complete, you should be able to run: – npm run start:devAnd see a website at http://localhost:8080/ – Sending anEmailWe will next have to setup the endpoint to ping and send the email.
  • This function handles sending the emails so all you have to do, is call the function to send an email, its much more clear and easier if your Sendgrid code needs to change.
  • function sendEmail( – parentCallback, – fromEmail, – toEmails, – subject, – textContent, – htmlContent – ) { – const errorEmails = []; – const successfulEmails = []; const sg = require(‘sendgrid’) async.parallel([ – function(callback) { – // Add to emails – for (let i = 0; i toEmails.length; i +=…
  • Now you can making your endpoint call this send email function: – async.parallel([ – function (callback) { – sendEmail( – callback, – [‘’, ‘Subject Line’, – ‘Text Content’, – ‘p style=font-size: 32px;HTML Content/p’ – ); – } – ], function(err, results) { – res.send({ – success: true, – message: ‘Emails…
  • errorEmails, – }); – });And you will have to change the from and to emails but if you run the server with npm run start:dev, open Postman and create a new POST request to You should see this response: – { – success: true, – message: Emails sent, – successfulEmails:…

Tags: Youtube video, boilerplate code, MERN boilerplate code, function, Medium post

  • I wanted some way to rotate a log file based on how many lines were written to it and no matter what I did I couldn’t get it to work the way I wanted it.
  • The most naive thing to do is use counters and boolean flags and in this version I’m not even using events because this is a good demonstration of the Node.js event loop and how there are no sequencing guarantees for I/O operations – – I highly recommend running this example…
  • In my next attempt I started using an event emitter to simulate what the incoming web traffic would look like and again you might think there is a way to make it work but there isn’t if all you are using are counters and boolean flags – – Seeing that…
  • But again even with a write-ahead-log there is no way in Node.js to guarantee that exactly 500 lines will be written to the write-ahead-log before it is archived.
  • Some WALs will have more and some will have fewer lines because the event loop does not guarantee sequencing of I/O operations.

Tags: boolean flags, in-memory buffer, I/O operations, actual explicit sequencing, event loop

  • Rather than putting all the onus on our Python web server to request up to 100+ keys at a time from S3, the decision was made to take advantage of Nodes easy async code patterns and great concurrency handling.
  • Most developers have heard about Nodes non-blocking I/O model; its great because it means all requests are handled asynchronously without blocking execution, or incurring any overhead (like with threads and processes) and as the developer you can be blissfully unaware whats happening in the backend.
  • We certainly didnt want to continue bouncing Octo every other week and we were both very interested in a promising case study that had cropped up on the internet: Handling 1 Million Requests per Minute with Go – – If the title wasnt tantalizing enough, the topic was on creating…
  • Our average response time from the service was almost cut in half, our timeouts (in the scenario that S3 was slow to respond) were happening on time, and our traffic spikes had minimal effects on the service.
  • Alongside Octo, we now have 3 other Golang services in production which power our realtime message system and serve up important metadata for our content.

Tags: Node, Octo, Node Octo, troublesome Node service, new Octo service

Top Node Courses

The Complete Node.js Developer Course (2nd Edition) (60,232 students enrolled)

By Andrew Mead
  • Build, test, and launch Node apps
  • Create Express web servers and APIs
  • Store data with Mongoose and MongoDB
  • Use cutting-edge ES6/ES7 JavaScript
  • Deploy your Node apps to production
  • Create real-time web apps with SocketIO

Learn more.

Angular (Angular 2+) & NodeJS - The MEAN Stack Guide (26,806 students enrolled)

By Maximilian Schwarzmüller
  • Build real Angular + NodeJS applications
  • Understand how Angular works and how it interacts with Backends
  • Connect any Angular Frontend with a NodeJS Backend
  • Use MongoDB with Mongoose to interact with Data on the Backend
  • Use ExpressJS as a NodeJS Framework
  • Provide a great user experience by using Optimistic Updating on the Frontend
  • Improve any Angular (+ NodeJS) application by adding Error Handling

Learn more.