We can test webhook callbacks with a little http server and a localtunnel.

Run server.js to spin up a local http server on port 8080. It just exposes a top-level route and will print the received header and payload of any request. Then create a localtunnel to have a non-local url that proxies all requests to localhost:8080.

First, install dependencies with npm install.

Then start the express server with npm start.

View mocha-guide-to-testing.js
// # Mocha Guide to Testing
// Objective is to explain describe(), it(), and before()/etc hooks
// 1. `describe()` is merely for grouping, which you can nest as deep
// 2. `it()` is a test case
// 3. `before()`, `beforeEach()`, `after()`, `afterEach()` are hooks to run
// before/after first/each it() or describe().
// Which means, `before()` is run before first it()/describe()
View test.js
import test from 'tape';
const before = test;
const after = test;
// beforeEach/afterEach rely on shared state.
// That's a big anti-pattern for testing.
// It's also silly to run something before and after
// ever test -- many of your tests won't need it.
A little script for generating HMACs.
For example ...
> ./ secret foo

collapsible markdown?


yes, even hidden code blocks!

print("hello world!")
scopes = []
View index.js
'use strict';
const Hapi = require('hapi');
const server = new Hapi.Server();
host: 'localhost',
port: 8000

Whether you use 2 spaces or 4 spaces, there are a few simple things that can make your node.js code easier to read. We've been using them in all the hapi modules for over 4 years now to great results. This list is by no means complete but it highlights the most useful elements that will give you immediate value in reducing bugs.

Required modules

JavaScript makes it harder than most languages to know where variables are coming from. Variables assigned required modules are particularly important because they represent a singleton object shared with the entire application. There are also globals and module globals, along with function variables and arguments.

Traditionally, variables starting with an uppercase letter represent a class that must be instantiated using new. This was an important semantic in the early days of JavaScript but at this point, if you don't know Date requires new Date() you are probably very new. We have adopted Upper Camel Case variable names for all module global variables

View custom-error.js
'use strict';
module.exports = function CustomError(message, extra) {
Error.captureStackTrace(this, this.constructor); =;
this.message = message;
this.extra = extra;
require('util').inherits(module.exports, Error);