Skip to content

Instantly share code, notes, and snippets.

@nirsky
Created December 17, 2019 12:17
Show Gist options
  • Save nirsky/a7f9b54f3a879579c23ec3de4e23798c to your computer and use it in GitHub Desktop.
Save nirsky/a7f9b54f3a879579c23ec3de4e23798c to your computer and use it in GitHub Desktop.
// node-handler.js
const fs = require('fs');
export const handle = () => {
fs.readFileSync(...);
...
};
// browser-handler.js
export const handle = () => { ... };
// index.js
const nodeHandler = require('./node-handler').handle;
const browserHandle = require('./browser-handler').handle;
const isNode = require('./config').isNode;
const handle = isNode ? nodeHandler : browserHandle;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment