diff --git a/README.md b/README.md
index 3362a87..c0a36d6 100644
--- a/README.md
+++ b/README.md
@@ -50,6 +50,7 @@ CGI-Node run on shared hosting sites running Apache. It can run along side PHP.
Action cgi-node /cgi-bin/cgi-node.js
AddHandler cgi-node .jss
+
Ensure you set the CGI_NODE_SESSIONDIR environment variable on your Apache instance
That's it!
diff --git a/src/CgiNodeConfig.js b/src/CgiNodeConfig.js
index 12ef20d..1963928 100644
--- a/src/CgiNodeConfig.js
+++ b/src/CgiNodeConfig.js
@@ -41,5 +41,5 @@ var CgiNodeConfig =
SessionCookie: 'CGI-NODE-SESSIONID',
SessionTimeOut: 15*60, // 15 minutes
- SessionPath: 'D:/Programs/nodejs/sessions/'
+ SessionPath: process.env.CGI_NODE_SESSIONDIR || 'D:/Programs/nodejs/sessions/'
};
diff --git a/src/CgiNodeSession.js b/src/CgiNodeSession.js
index 8493b35..51f69b8 100644
--- a/src/CgiNodeSession.js
+++ b/src/CgiNodeSession.js
@@ -73,6 +73,11 @@ function CgiHttpSession(request, response)
this.id = (request.cookies.hasOwnProperty(CgiNodeConfig.SessionCookie) ? request.cookies[CgiNodeConfig.SessionCookie] : this.create());
var path = Path.join(CgiNodeConfig.SessionPath, this.id);
+ // If the path doesn't exist, then create it.
+ if (! FS.existsSync(CgiNodeConfig.SessionPath)) {
+ FS.mkdirSync(CgiNodeConfig.SessionPath, 0700);
+ }
+
// If the file does not exist then create another ID.
if (!FS.existsSync(path)) this.id = this.create();
diff --git a/src/build.js b/src/build.js
index da7c76d..5f96ccb 100644
--- a/src/build.js
+++ b/src/build.js
@@ -145,15 +145,30 @@ var HTTP = require('http');
var QueryString = require('querystring');
// Specifies the path to where node executable exists. NOTE: windows machines require the double quotes.
-var nodeExecPathLinux = '/usr/bin/nodejs'
+var nodeExecPathLinux = '/usr/bin/env node';
var nodeExecPathWindows = '"D:/Programs/nodejs/node.exe"';
+var nodeExecPath;
// The list of files to build in the correct order.
-var files = ['CgiNodeConfig.js', 'CgiNodeContext.js', 'CgiNodeSession.js', 'CgiNodeResponse.js', 'CgiNodeRequest.js', 'CgiNodeParser.js', 'CgiNode.js'];
+var files = [
+ 'CgiNodeConfig.js',
+ 'CgiNodeContext.js',
+ 'CgiNodeSession.js',
+ 'CgiNodeResponse.js',
+ 'CgiNodeRequest.js',
+ 'CgiNodeParser.js',
+ 'CgiNode.js'
+ ];
+
+if (FS.existsSync(nodeExecPathLinux)) {
+ nodeExecPath = nodeExecPathLinux;
+} else {
+ nodeExecPath = nodeExecPathWindows;
+}
// The output path and file name.
var output = '../cgi-bin/cgi-node';
// Create the build class and run it.
var build = new CgiNodeBuilder();
-build.run(files, output, nodeExecPathWindows);
+build.run(files, output, nodeExecPath);