Musical middleware for ExpressJS

tl;dr: Play a noise or song when a route is hit, just a toy

// $ npm i musicalroutes
var app = require('express')();
var musicalroutes = require("musicalroutes");
app.use("/tunes", musicalroutes());


Node 4.2.6+, Mac only for now

— — — — — — —

The REAL musical Route

On a recent project I became reacquainted with old friend ExpressJS. I was struck by how downright pleasant it (still) is to mount/use 3rd-party middleware. When it’s the right tool for the job, all you really need app.use(middleware({opts}) and you’re done. I realized that I had never really bothered to investigate app.use’s implementation to mount middleware, so I took a look.

The product of all that codebase spelunking is the musicalroutes middleware.

How can we make the server louder?

While $ npmusic transformed the way we install dependencies (by making the process louder with music), the public was still clamoring for more opportunities to make noise. musicalroutes is the natural next step.

You use musicalroutes like you would any other Express middleware — install it, require it, mount it— then you’re in business.


var app = require('express')();
var musicalroutes = require("./index.js");
var port = process.env.port || 8080;
app.use("/tunes", musicalroutes()); #Hit /tunes, plays a random song
app.listen(port, function() {
console.log("listening on ", port);


Source: Custom audio source (absolute path or youtube URL)
app.use("/tunes", musicalroutes({"source":""});
Predicate: Optional function that resolves to true/false that determines if audio source plays (predicate function receives the full req/res objects as parameters)
app.use("/products/:id", musicalroutes({
"source": "",
predicate: (req, res) => {
if ( == 7) {
return true;
} else {
return false
}), function(req, res, next) {
res.send("You picked " +;

Note: If things get too loud, to shut everything up, just kill the server

Further Reading