Making a REST API: How do I route a filepath using express for node

var express = require('express');

var app = express();
app.get('/files/:service/:op/:file', function(req, res){
  console.log(req.params.file)
})

app.listen(3000);

Calling http://localhost:3000/files/farm/get/chicken will log chicken. Calling http://localhost:3000/files/farm/get/barn/yard/chicken will log barn.

How can I make an Express app.VERB(path, callback) path log barn/yard/chicken?

Change your route to something like this:

app.get('/files/:service/:op/*', function(req, res){
  console.dir(req.params);
  console.log(req.params[0]); // this is what you want
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('OK');

});

Notice how the last parameter was changed to an * so that it takes single values (like chicken) or multi-values (like barn/yard/chicken). The issue here is that the slash character is used to split the URL components but you want to sometimes split the values but not others. The * will automatically lump the last set of values (1 or many) into a single element.

See http://expressjs.com/api.html#req.params

Try this:

console.log(req.params.service + "/" + req.params.op + "/" + req.params.file);