From ca3bf8e83e2a741cdfa3aab5db6b9ee46d31176d Mon Sep 17 00:00:00 2001 From: Soam Vasani Date: Thu, 23 Feb 2017 10:19:42 -0800 Subject: [PATCH] Symlink user function's node_modules to server's node_modules (#133) Fixes #132 --- environments/nodejs/server.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/environments/nodejs/server.js b/environments/nodejs/server.js index 4b3d83f0..591793d2 100644 --- a/environments/nodejs/server.js +++ b/environments/nodejs/server.js @@ -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;