Last active
April 16, 2020 11:05
-
-
Save svsh227/4cc4fe394fb41e68b13e01b7849cd9bb to your computer and use it in GitHub Desktop.
STEP 3: Create your server.js file
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'); | |
const app = express(); | |
const port = 3300; | |
app.get('/message', function (req, res) { | |
res.send('This is the message'); | |
}); | |
app.get('/media', function (req, res) { | |
var response = { | |
podcasts: [{ | |
"description": "some text", | |
"id": 574, | |
"title": "Why long-term value is a winning bet", | |
"media": "podcast", | |
"publishedDate": "2018-12-19T18:00:00.000Z", | |
"isLive": true, | |
"isDeleted": false, | |
"link": "https://podcasts.com/574", | |
"createdAt": "2018-12-20T06:30:00.618Z", | |
"updatedAt": "2019-01-31T06:30:00.864Z" | |
}], | |
total: 1 | |
} | |
if (response.podcasts.length > 0) { | |
res.send(response); | |
} else { | |
var errorObj = { | |
httpCode: 404, | |
message: 'NOT_FOUND', | |
description: 'The resource referenced by request does not exists.', | |
details: 'Podcast is not available' | |
} | |
res.status(404); | |
res.send(errorObj) | |
} | |
}); | |
app.listen(port, function () { | |
console.log("\nServer is running on port " + port); | |
}); | |
module.exports = app; // for testing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment