Created
October 2, 2018 02:44
-
-
Save ganeshkbhat/32e40ec767403d05260d02a96a7afdcb to your computer and use it in GitHub Desktop.
ExpressJS Series: Basic Server - Middleware Usage
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 express = require('express'); | |
let app = express(); | |
const myFirstMiddleware = function(req, res, next) { | |
console.log('My logger'); | |
next(); | |
}; | |
app.use(myFirstMiddleware); | |
app.get('/', function(req, res) {res.status(200).send({status: "running", time: Date.now()})}); | |
/* POST */ | |
app.post('/', function(req, res) {res.status(200).send({status: "running", time: Date.now()})}); | |
/* PUT */ | |
app.put('/', function(req, res) {res.status(200).send({status: "running", time: Date.now()})}); | |
/* PATCH */ | |
app.patch('/', function(req, res) {res.status(200).send({status: "running", time: Date.now()})}); | |
/* DELETE */ | |
app.delete('/', function(req, res) {res.status(200).send({status: "running", time: Date.now()})}); | |
/* OPTIONS */ | |
/* | |
app.options('/', function(req, res) {res.status(200).send({status: "running", time: Date.now()})}); | |
*/ | |
app.post('/api/myform/:categoryId', function(req, res) { | |
res.status(200).send({paramValues: req.params.categoryId, queryParamValues: req.query.create + ' ' + req.query.notify}); | |
}); | |
const host = "127.0.0.1"; | |
const port = 9001; | |
app.listen(host, port, function() {console.log("Server started")}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment