-
Notifications
You must be signed in to change notification settings - Fork 56
Running in Cloud9
bjouhier edited this page Jul 19, 2011
·
10 revisions
You can use streamline with Cloud9. Here are some instructions to get started with a local install on mac OS X.
Install streamline locally:
npm install streamline
Install Cloud9 locally:
git clone https://github.com/ajaxorg/cloud9.git
cd cloud9
mkdir ~/myproject
node bin/cloud9.js -w ~/myproject
Inside Cloud9 IDE, create 3 Javascript files in the myproject
folder:
// server.js:
var http = require('http');
require('streamline');
var foo = require('./foo');
http.createServer(function (req, res) {
foo.dispatch(req, res, function(err) {
if (err) {
res.writeHead(500, { "Content-Type": "text/plain" });
res.end(err.message + "\n" + err.stack);
}
});
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
// foo_.js
var fs = require('fs');
exports.dispatch = function(request, response, _) {
var files = fs.readdir('/', _).join('\n');
response.writeHead(200, { "Content-Type": "text/plain" });
response.end(files);
}
// foo.js
<empty>
Then, click on the run button and choose server.js
as main script to run.
Point your browser to http://127.0.0.1:8124/
You should see a listing of your root directory
Note: you cannot use streamline code directly in the server.js
file because this file is loaded by node
rather than node-streamline
. So, you have to put the streamline code in a separate module that you require from the main script.