Skip to content

Instantly share code, notes, and snippets.

@ThunderWiring
Last active July 20, 2018 07:22
Show Gist options
  • Save ThunderWiring/a337daec7405e776e83e9c309705e459 to your computer and use it in GitHub Desktop.
Save ThunderWiring/a337daec7405e776e83e9c309705e459 to your computer and use it in GitHub Desktop.
creating a simple HTTP server using NodeJs and ExpressJs which handles a POST request
const express = require('express');
const bodyParser = require("body-parser");
const port = 3000;
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
const server = app.listen(port, '<ip_address>');
app.post('/post-request-url', (request, response) => {
response.send('response from server to the post request!');
})
server.on('listening', (error) => {
if (error) {
console.error('error ancountered: ' + error);
} else {
console.log('Express server started on port %s at %s',
server.address().port,
server.address().address);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment