hello.js

var please = require('share');
console.log('thank you');

Monday, 29 April, 2019 UTC

Understand how to approach designing queues in Node

Understand how to approach designing queues in Node

A new scenario you might not have faced before: you have a long running task (like saving to a bunch of different databases, or processing video) that takes a while to process and it’s currently causing your REST API response times to be way too slow ... more


Friday, 29 March, 2019 UTC

Should you log the Express req object and external API responses?

Should you log the Express req object and external API responses?

Logging as much information as you need to be able to troubleshoot, understand what happened during a session, and even for analytics purposes is something all apps need to have in place before going to production. You’ve likely got some logging in place ... more


Wednesday, 6 March, 2019 UTC

Executing arrays of async/await JavaScript functions in series vs. concurrently

Executing arrays of async/await JavaScript functions in series vs. concurrently

When dealing with an array of async/await functions (which are Promises), it can be tricky to figure out how to execute them all in series (one-at-a-time) and how to call them in concurrently (not one-at-a-time, executed during overlapping time periods). ... more


Tuesday, 26 February, 2019 UTC

Applying the callback -> async/await conversion process to a real-world example

Applying the callback -> async/await conversion process to a real-world example

This is a follow-up to my post on the process for converting callbacks to Promises and to async/await functions. In that post I stuck to using setTimeout as an easy way to introduce some asynchronicity into the code. But I understand that for some people, ... more


Wednesday, 13 February, 2019 UTC

Why should you separate Controllers from Services in Node REST API’s?

Why should you separate Controllers from Services in Node REST API’s?

This is a follow-up to my last post, What is the difference between Controllers and Services in Node REST API’s?. In that post we covered the differences between the two, and what kind of logic goes where, but only briefly touched on why you might want ... more


Tuesday, 5 February, 2019 UTC

What is the difference between Controllers and Services in Node REST API’s?

What is the difference between Controllers and Services in Node REST API’s?

If you’ve built out a REST API in Node (or other languages, for that matter), you’ve likely used the concept of “controllers” to help organize your application. Maybe you put your calls to your database or models there, called some other endpoints, and ... more


Tuesday, 15 January, 2019 UTC

How to rewrite a callback function in Promise form and async/await form in JavaScript

How to rewrite a callback function in Promise form and async/await form in JavaScript

“You should really use Promises or async/await here to make this more readable” How many times have you posted some code snippet when trying to get an answer to your question, and someone ends up pestering you about this? Now, on top of whatever problem ... more


Saturday, 5 January, 2019 UTC

expect(await fn()) vs await expect(fn()) for error tests with chai-as-promised

expect(await fn()) vs await expect(fn()) for error tests with chai-as-promised

The problem scenario Ah, writing tests for errors. It’s fun, isn’t it? Have you ever written a unit test expecting to catch an error with Chai, and gotten something like the below? I don’t understand why expect(await fn()).to.be.rejectedWith( I’m an ... more


Tuesday, 27 November, 2018 UTC

Why you should isolate Express from the rest of your Node application

Why you should isolate Express from the rest of your Node application

You might have heard that you should “always layer your app” and “never let logic leak into other layers” before. Those are statements made all over your favorite blogs, in “must read” programming books, and at tech meetups and conferences. But you might ... more


Wednesday, 21 November, 2018 UTC

Real world testing recipes: Node service that calls an external API

Real world testing recipes: Node service that calls an external API

This is the next post in my series on knowing what to test in your Node applications by applying recipes to real-world scenarios . In the first one, we went over scenarios you should cover in your tests when calling a database from a Node service. In ... more


Tuesday, 6 November, 2018 UTC

Project structure for an Express REST API when there is no “standard way”

Project structure for an Express REST API when there is no “standard way”

Do any GitHub or Google search for REST API structures using Node + Express and you’ll find very few of them follow the same organization. What’s even worse is, while there are lots of good tutorials out there, many of them have no structure at all. ... more


Tuesday, 23 October, 2018 UTC

Avoid manually prepending ‘/api’ to every Express route with this simple method

Avoid manually prepending ‘/api’ to every Express route with this simple method

Have you ever been frustrated by having to always manually add ‘/api’ to the beginning of each of your Express routes? Usually I see this come in two forms: Form 1: In app.js file: app.use('/api/users', require('./routes/users')) app.use('/api/posts', ... more


Thursday, 11 October, 2018 UTC

How to find the best open source Node.js projects to study for leveling up your skills

How to find the best open source Node.js projects to study for leveling up your skills

To senior developer: “How did you get so good at programming?” “I don’t know, I guess I just wrote a lot of code, and read a lot of it too…” Have you ever tried finding an open source Node.js project that you could study to level up your skills, only ... more


Wednesday, 26 September, 2018 UTC

Separating logic from Express routes for easier testing

Separating logic from Express routes for easier testing

Have you ever been confused on how to structure your Express applications in a way that makes them testable? As with most things in the Node.js world, there are many ways of writing and structuring Express apps. The best place to start though is usually ... more


Thursday, 6 September, 2018 UTC

Why isn’t this unit test catching an error from this async/await function?

Why isn’t this unit test catching an error from this async/await function?

When you’re writing unit tests for asynchronous functions in JavaScript, one test case you’ll usually want to have is making sure the async function throws an error in case of an error scenario. Let’s imagine writing a test for an item function that ... more


Tuesday, 28 August, 2018 UTC

Know what to test using these recipes: Node service that calls a database

Know what to test using these recipes: Node service that calls a database

If you’ve ever gone through a JavaScript or Node unit testing tutorial, it can be difficult to find anything that shows you what you should be testing – what scenarios to cover, what to write tests for, etc. It’s easy to find tutorials that take you ... more


Tuesday, 31 July, 2018 UTC

Tried TDD and didn’t realize the benefits? Try it the next time you get writer’s block

Tried TDD and didn’t realize the benefits? Try it the next time you get writer’s block

Have you ever tried Test-Driven Development (TDD) thinking it would be the “holy grail” it’s often made out to be, only to end up feeling like it was pointless? Maybe it didn’t add any benefit to your code. Maybe writing your test first, then the code ... more


Wednesday, 11 July, 2018 UTC

Using the `debug` module to avoid polluting your application logs with logs from Node modules

Using the `debug` module to avoid polluting your application logs with logs from Node modules

Have you ever added logging to your custom Node modules, thinking you’ll benefit from all that extra information, only to find that when you add the modules as dependencies, run npm install and npm start , your application logs start looking like the ... more


Tuesday, 3 July, 2018 UTC

Why should your Node.js application not handle log routing?

Why should your Node.js application not handle log routing?

It is not the responsibility of the application to route logs. 12 Factor says that logs should go to STDOUT. WAT? WHY? I just configured my whole application code to write logs to custom log files. What’s wrong with that? Logging is one of those things ... more


Wednesday, 20 June, 2018 UTC

Should you use a logging framework or console.log() in Node?

Should you use a logging framework or console.log() in Node?

The console module is usually the first tool Node.js developers reach for when handling logging in an application. It’s easy to use, native to the platform, and easy to read. But then you might stumble upon a logging framework like Winston or Bunyan. ... more


Sunday, 10 June, 2018 UTC

Explain JavaScript unit testing like I’m five

Explain JavaScript unit testing like I’m five

Unit testing is so critical to good software development, yet for beginners (and many experienced professionals as well) it’s something that can feel alien and uncomfortable at first. It might be something you know you should be doing, but haven’t had ... more


Wednesday, 23 May, 2018 UTC

Which of the 635000 npm modules do I choose?

Which of the 635000 npm modules do I choose?

If you’ve spent any time in the Node or Front End JavaScript world, you know there are hundreds of thousands of modules to choose from. Developers constantly ask things and express pain like: “What’s eating away at us is which modules to choose…” “What ... more


Monday, 7 May, 2018 UTC

../../../../ escaping relative path require hell in Node.js

../../../../ escaping relative path require hell in Node.js

../../../../../Having/to/write/code/like/this when you’re requiring local modules is a sight for sore eyes. Some consider it one of the bigger pain points with Node due to poor readability when trying to figure out where that module is in the directory ... more


Sunday, 15 April, 2018 UTC

Do you need to queue jobs in Node.js?

Do you need to queue jobs in Node.js?

If you’re coming to Node.js from a more synchronous language/environment such as Ruby on Rails or Java, the concept of asynchronous processing can be confusing. All the literature talks about Node being async, so it’s easy to get the understanding that ... more


Sunday, 25 March, 2018 UTC

Why does async/await in a .forEach not actually await?

Why does async/await in a .forEach not actually await?

If you’re trying to loop over a list while using async/await in Node.js (or the browser, for that matter), reaching for the .forEach array function might seem like a natural choice. Let’s say you go that route, fire up your tests or your application, ... more