Skip to content

Instantly share code, notes, and snippets.

@guptasanchit90
Created June 6, 2016 06:40
Show Gist options
  • Save guptasanchit90/6dfc4022232efaf6a044dd329476f7c4 to your computer and use it in GitHub Desktop.
Save guptasanchit90/6dfc4022232efaf6a044dd329476f7c4 to your computer and use it in GitHub Desktop.
Simple Image hosting from file system in Node.js using express routes
var express = require('express');
var app = express();
var fs = require('fs');
app.get('/get', function (req, res) {
res.sendFile(__dirname + '/' + req.query.type + '/' + req.query.name);
})
app.get('/list', function (req, res) {
fs.readdir(__dirname + '/' + req.query.type, function(err, items) {
var output = '{"Files":' + JSON.stringify(items) + '}';
res.send(output);
});
})
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment