The following examples illustrate defining simple routes. Respond with Hello World! on the homepage: //get method for retrieving data. app.get('/', function (req, res) { res.send('Hello World!') }) Save Respond to POST request on the root route (/), the application’s home page: //send method for sending data. app.post('/', function (req, res) { res.send('Got a POST request') }) Save Respond to a PUT request to the /user route: //put request to app.put('/user', function (req, res) { res.send('Got a PUT request at /user') }) Save Respond to a DELETE request to the /user route: app.delete('/user', function (req, res) { res.send('Got a DELETE request at /user') })
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter