-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (32 loc) · 921 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require('newrelic');
const express = require('express');
const app = express();
const { NEW_RELIC_KEY } = process.env;
console.log('NEW_RELIC_KEY', NEW_RELIC_KEY);
function badDatabaseConnection() {
// Let's pretend you tried to access a database and it failed.
throw new Error('Unable to connect to database');
}
function getBookById(id) {
// Let's pretend the book ID cannot be found
throw new Error(`No book found for ID '${id}'`);
}
app.get('/', (req, res) => {
res.send('<h1>Yo!</h1>');
});
app.get('/hello', (req, res) => {
const { name } = req.query;
res.send(`<h3>Hello ${name || ''}</h3>`);
});
app.get('/book/:id', (req, res) => {
const { id } = req.params;
if (id === '8675309') {
res.send('<h1>I got yo numba!!</h1>');
} else {
getBookById(id);
}
});
const port = 2112;
app.listen(port, () => {
process.stdout.write(`Our awesome app is listening on port ${port}`);
});