Skip to content

Instantly share code, notes, and snippets.

@ganeshkbhat
Last active September 19, 2022 02:40
Show Gist options
  • Save ganeshkbhat/471c635c9a40b3aca97eb6705b1d4ce9 to your computer and use it in GitHub Desktop.
Save ganeshkbhat/471c635c9a40b3aca97eb6705b1d4ce9 to your computer and use it in GitHub Desktop.
ExpressJS: API Template
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");
});
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