Skip to content

Instantly share code, notes, and snippets.

@clarkhacks
Last active March 22, 2019 18:58
Show Gist options
  • Save clarkhacks/5e761bf8e7da4ca0d1d6d0029e9f8c0f to your computer and use it in GitHub Desktop.
Save clarkhacks/5e761bf8e7da4ca0d1d6d0029e9f8c0f to your computer and use it in GitHub Desktop.
var express = require('express');
var serveIndex = require('serve-index');
var app = express();
app.use('/public', serveIndex('files')); // shows you the file list
app.use('/public', express.static('files')); // serve the actual files
app.get("/clear", function(req, res) {
const fs = require('fs');
const path = require('path');
const directory = '/motion';
fs.readdir(directory, (err, files) => {
if (err) throw err;
for (const file of files) {
fs.unlink(path.join(directory, file), err => {
if (err) throw err;
});
}
});
});
app.listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment