npm install
npm startThe API server should run on port 5000
Open the broswer and browse the following url
| const express = require('express') | |
| const compression = require('compression') | |
| const PORT = process.env.PORT || 5000 | |
| const Kmb = require('js-kmb-api').default | |
| let localStorage | |
| const kmb = new Kmb('zh-hant', localStorage) | |
| express() | |
| .use(compression()) | |
| .get('/', (req, res) => { | |
| res.send('Hello World!') | |
| }) | |
| .get('/getETAsByRoute/:route/:bound/:serviceType', (req, res) => { | |
| kmb.getRoutes(req.params.route) | |
| .then(data => data.find(route => route.bound === parseInt(req.params.bound))) | |
| .then(route => route.getVariants()) | |
| .then(data => data.find(route => route.serviceType === parseInt(req.params.serviceType))) | |
| .then(variant => variant.getStoppings()) | |
| .then(stoppings => Promise.all(stoppings.map(stopping => stopping.getEtas()))) | |
| .then(data => res.send(data)) | |
| }) | |
| .get('/getETAsByStopID/:stopID', (req, res) => { | |
| const stop = new kmb.Stop(req.params.stopID) | |
| stop.getStoppings() | |
| .then(stoppings => Promise.all(stoppings.map(stopping => stopping.getEtas()))) | |
| .then(data => res.send(data)) | |
| }) | |
| .listen(PORT, () => console.log(`Listening on ${PORT}`)) |
npm install
npm startThe API server should run on port 5000
Open the broswer and browse the following url
| { | |
| "name": "kmb_api", | |
| "version": "0.1.0", | |
| "description": "A sample KMB API", | |
| "main": "index.js", | |
| "scripts": { | |
| "start": "node index.js" | |
| }, | |
| "dependencies": { | |
| "compression": "^1.7.4", | |
| "express": "^4.17.1", | |
| "js-kmb-api": "^3.2.5" | |
| }, | |
| "keywords": [ | |
| "node", | |
| "heroku", | |
| "express" | |
| ], | |
| "license": "MIT" | |
| } |