Skip to content

Instantly share code, notes, and snippets.

@doron2402
Last active April 25, 2018 19:04
Show Gist options
  • Save doron2402/d0d31d5bb86cf99fd506fcf4cf501daa to your computer and use it in GitHub Desktop.
Save doron2402/d0d31d5bb86cf99fd506fcf4cf501daa to your computer and use it in GitHub Desktop.
Simple upload server using single dependecy
'use strict';
/**
For full repo go to:
https://github.com/doron2402/simple-upload-files
**/
const http = require('http');
const uploaderRoute = require('./routes/uploader');
const formRoute = require('./routes/form');
const notFoundRoute = require('./routes/notFound');
const PORT = 3000;
http.createServer(function (req, res) {
if (req.url.toLowerCase() === '/upload' && req.method.toLowerCase() === 'post') {
return uploaderRoute(req, res);
}
else if (req.url.toLowerCase() === '/form' && req.method.toLowerCase() === 'get') {
return formRoute(req, res);
}
else {
return notFoundRoute(req, res);
}
}).listen(PORT, (err) => {
if (err) {
throw err;
}
console.log(`Server is running ${PORT}`);
});
@doron2402
Copy link
Author

starting...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment