Symlink user function's node_modules to server's node_modules (#133)

Fixes #132
This commit is contained in:
Soam Vasani
2017-02-23 10:19:42 -08:00
committed by GitHub
parent 92cd5334ec
commit ca3bf8e83e
+11
View File
@@ -1,6 +1,7 @@
'use strict';
const fs = require('fs');
const path = require('path');
const process = require('process');
const express = require('express');
const app = express();
@@ -18,6 +19,16 @@ if (!argv.port) {
argv.port = 8888;
}
// Node resolves module paths according to a file's location. We load
// the file from argv.codepath, but tell users to put dependencies in
// the server's package.json; this means the function's dependencies
// are in /usr/src/app/node_modules. We could be smarter and have the
// function deps in the right place in argv.codepath; but for now we
// just symlink the function's node_modules to the server's
// node_modules.
fs.symlinkSync('/usr/src/app/node_modules', `${path.dirname(argv.codepath)}/node_modules`);
// User function. Starts out undefined.
let userFunction;