Skip to content

Instantly share code, notes, and snippets.

View caridy's full-sized avatar

Caridy Patiño caridy

  • Salesforce, Inc.
  • Miami, FL.
  • X @caridy
View GitHub Profile

Proposal for Extending Express Apps

Creating npm packages which extend the functionality of Express apps has become a major thing we've been doing. There are several approaches we can take, from messing with the Express object prototypes, to creating a function in which an express app is passed in. After trying the former, I'm now a fan of the latter.

The Issues with Extending Express

Extending the Express object prototypes has issues. The running Node.js process may have multiple versions of express, and in order to extend the prototypes you need to require('express'). This means that you might get a different express module instance than the one the main app is created from.

Both approaches suffer from extending something more than once. Similar to how there may be multiple version of express in the running Node.js process, there can also be multiple copies of the extension modules. If the app developer needs to rely on a different version of an Express ext

/* global HackToInferCallerFilename */
'use strict';
var REGEX_CALLER_FILENAME = /\(([^:]+)\:\d+\:\d+\)/g;
module.exports = function () {
var filename;
try {
HackToInferCallerFilename;
<!doctype html>
<html>
<head><title>Test Page</title></head>
<body class="yui-skin-sam">
<!-- Bootstrap Script //-->
<script type="text/javascript" src="../../../../yui3/build/yui/yui-debug.js"></script>
<!-- Initialization process //-->
<script type="text/javascript">
YUI_config = {
<!doctype html>
<html>
<head><title>Test Page</title></head>
<body class="yui-skin-sam">
<!-- Bootstrap Script //-->
<script type="text/javascript" src="../../../../yui3/build/yui/yui-debug.js"></script>
<!-- Initialization process //-->
<script type="text/javascript">
YUI_config = {
Y.namespace('Plugin').NodeAccordion = Y.Base.create("NodeAccordion", Y.Plugin.Base, [], {
// Prototype Properties for NodeAccordion
/**
* @property _root
* @description Node instance representing the root node in the accordion.
* @default null
* @protected
* @type Node
/**
* <p>The Dispatcher satisfies a very common need of developers using the
* YUI library: dynamic execution of HTML Fragments or remote content. Typical strategies to
* fulfill this need, like executing the innerHTML property or referencing remote
* scripts, are unreliable due to browser incompatibilities. The Dispatcher normalize
* this behavior across all a-grade browsers.
*
* <p>To use the Dispatcher Module, simply create a new object based on Y.Dispatcher
* and pass a reference to a node that should be handled.</p>
*
/**
* <p>The Accordion Node Plugin makes it easy to transform existing
* markup into an accordion element with expandable and collapsable elements,
* elements are easy to customize, and only require a small set of dependencies.</p>
*
*
* <p>To use the Accordion Node Plugin, simply pass a reference to the plugin to a
* Node instance's <code>plug</code> method.</p>
*
* <p>
YUI_config = {
// standard YUI_config configuration
combine: true,
filter: 'min',
// event binder configuration starts here
eventbinder: {
// set of options that should be preserved for every event (all optional)
ev: {
ctrlKey: 0,
altKey: 0,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>test</title>
</head>
<body>
<!-- YUI 3 Seed //-->