Skip to content

Instantly share code, notes, and snippets.

@chathurawidanage
Created February 24, 2018 11:51
Show Gist options
  • Save chathurawidanage/464d97dd780398f3184bc783a6447ea9 to your computer and use it in GitHub Desktop.
Save chathurawidanage/464d97dd780398f3184bc783a6447ea9 to your computer and use it in GitHub Desktop.
const { execSync } = require('child_process');
let oldRequire = require;
require = function(module) {
try{
oldRequire.resolve(`/tmp/node_modules/${module}`);
}catch(e){
execSync(`npm install --prefix /tmp --save ${module}`);
}
return oldRequire(`/tmp/node_modules/${module}`);
}
/* JUST FORGET EVERYTHING AND START YOUR CODE FROM THIS POINT ONWARDS*/
exports.handler = (event, context, callback) => {
if(event.task==="reverse"){
let reverseString = require('reverse-string');
callback(null, reverseString(' = evitavired'));
}else{
let mathjs = require('mathjs');
callback(null, mathjs.derivative('x^2 + x', 'x').toString());
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment