I have a growing node.js server application, and I'd like to get it split into several files. Here is a working code snippet demonstrating what monolithic server.js roughly looks like:
var express = require('express');
var app = express();
// other initialization code etc
//************** start of part to be moved foo.js
var fooTestData = {data: "data", id:1};
app.get("/foo/ajax", function(req, res) {
res.json(fooTestData);
});
// more REST stuff and other foo-specific code
//************** end of part to be moved
// more stuff which remains in server.js
// http://localhost:8888/foo/ajax
app.listen(8888);
An ideal answer has two pieces of code with identical functionality: What server.js looks like after moving the indicated part, and what foo.js looks like with copied code and any needed extra code.