Skip to content

Instantly share code, notes, and snippets.

@devansvd
Last active April 28, 2020 12:57
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 devansvd/ca5a0e1946f73049d0e4e9548e188e13 to your computer and use it in GitHub Desktop.
Save devansvd/ca5a0e1946f73049d0e4e9548e188e13 to your computer and use it in GitHub Desktop.
Nodejs Boiler plate code
const http = require('http');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.all('*',function(req,res,next){
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'OPTIONS,GET,POST,PUT,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
})
app.set('port', (process.env.PORT || 5000));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.post("/post", function(req, res){
console.log("Post")
return res.send("Post pinging");
});
app.get("/", function(req, res){
console.log("Get")
return res.send("Get pinging");
});
http.createServer(app).listen(app.get('port'), function(){
console.log("server is running ...");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment