Last active
April 28, 2020 12:57
-
-
Save devansvd/ca5a0e1946f73049d0e4e9548e188e13 to your computer and use it in GitHub Desktop.
Nodejs Boiler plate code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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