Skip to content

Instantly share code, notes, and snippets.

@jescalan
jescalan / fn.js
Last active December 22, 2016 14:33
lazy-loading require in node
/**
* Requires a library, but only loads it when it's actually used.
*
* lazy_require('fs');
* fs.readFileSync('example.js');
*
* var wow = lazy_require('fs');
* wow.readFileSync('example.js');
*
* @param {String} lib - name of the lib you want to load
@branneman
branneman / better-nodejs-require-paths.md
Last active April 27, 2024 04:16
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@tahajahangir
tahajahangir / example-mod-wsgi.py
Last active April 22, 2024 00:37 — forked from branneman/example-mod-wsgi.py
Python (2&3 compatible) Equivalent to phpinfo()
def application(environ, start_response):
from pyinfo import pyinfo
output = pyinfo()
# or pyinfo([('custom key', 'custom value'), ...])
start_response('200 OK', [('Content-type', 'text/html')])
return [output]