Skip to content

Instantly share code, notes, and snippets.

@S0ngyuLi
Last active May 2, 2018 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save S0ngyuLi/8f1da1a5fa849803d2d458308537a1b2 to your computer and use it in GitHub Desktop.
Save S0ngyuLi/8f1da1a5fa849803d2d458308537a1b2 to your computer and use it in GitHub Desktop.
image server
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
if (req.method == 'POST') {
console.log("POST");
var body = '';
req.on('data', function (data) {
body += data;
console.log("Partial body: " + body);
});
req.on('end', function () {
console.log("Body: " + body);
});
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('post received');
console.log("Recerive a Post ");
}
else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('post received');
}
});
server.listen(port, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment