Last active
September 19, 2022 02:40
-
-
Save ganeshkbhat/471c635c9a40b3aca97eb6705b1d4ce9 to your computer and use it in GitHub Desktop.
ExpressJS: API Template
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
var app = require("express"); | |
const mainRoute = require("./main.route") | |
app.use(mainRoute); | |
app.all("*", function(req, res, next) { | |
res.send("Hello World Route Present"); | |
}) | |
app.listen(8000, function() { | |
console.log("Server started at 8000"); | |
}); |
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
var app = require("express"); | |
var pathRoute = "/events"; | |
function allRequest(req, res, next) { | |
res.send('Hello World All request!'); | |
} | |
function getRequest(req, res, next) { | |
res.send('Hello World Get request!'); | |
} | |
function postRequest(req, res, next) { | |
res.send('Hello World Post request!'); | |
} | |
function putRequest(req, res, next) { | |
res.send('Hello World Put request!'); | |
} | |
function patchRequest(req, res, next) { | |
res.send('Hello World Patch request!'); | |
} | |
function deleteRequest(req, res, next) { | |
res.send('Hello World Delete request!'); | |
} | |
function optionsRequest(req, res, next) { | |
res.send('Hello World Options request!'); | |
} | |
app.route(pathRoute) | |
.all(allRequest) | |
.get(getRequest) | |
.put(postRequest) | |
.post(putRequest) | |
.patch(patchRequest) | |
.delete(deleteRequest) | |
.options(optionsRequest); | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment