Files
  • index.js
  • package-lock.json
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const express = require('express');
const app = express();

// Sending content to response at root
app.get('/', (req, res) => res.send('GET request into root.'));

// Sending JSON response under API route
app.get('/api/', (req, res) => res.json({data: {
	title: 'Data API returning JSON',
	list: [9,7,6,3,1],
	datetime: new Date().toLocaleDateString()
}}));

// Any other route intercepted here
app.use((req, res) => res.send('Any other path - Denied!'));

app.listen(3000,() => console.log('Server listening to 3000'));
node v9.7.1 linux/amd64