Location Data Server for NodeJS

I have built my first NodeJS package that provides a json backend to api.piperpal.com and published it on https://www.npmjs.com/package/location-server/

const express = require(‘express’);
const bodyParser = require(‘body-parser’);
const axios = require(‘axios’);

const app = express();
const port = 3000;

app.use(bodyParser.urlencoded({ extended: true }));

app.get(‘/location-server-time’, async (req, res) => {
const { timeOut, timeBegin, timeEnd } = req.query;
try {
const response = new Date().getTime();
} catch (error) {
res.status(500).json({ error: ‘Error fetching time’ });

app.get(‘/location-server-data’, async (req, res) => {
const { service, glat, glon, radius } = req.query;
try {
const response = await axios.get(https://api.piperpal.com/location/json.php?service=${service}&glat=${glat}&glon=${glon}&radius=${radius});
const locations = response.data.locations;
} catch (error) {
res.status(500).json({ error: ‘Error fetching data’ });

app.listen(port, () => {
console.log(Location Data Server listening on port ${port});

Source Code: https://gitlab.com/ole.aamot/location-server/-/blob/main/location-server.cjs?ref_type=heads

git clone https://gitlab.com/ole.aamot/location-server

npm install axios express

cd location-server/

node location-server.cjs

> location-server@8.0.1 start

> node location-server.cjs

Location Data Server listening on port 3000

CGI-params service, glat, glon and radius are the ranges for the search that is executed by axios.get() to the response variable

const response = await axios.get(`https://api.piperpal.com/location/json.php?service=${service}&glat=${glat}&glon=${glon}&radius=${radius}`);

I write the response with res.json().

I have written more about Piperpal 7.0 JSON API and Piperpal Mobile on https://www.piperpal.com/mobile/ and http://www.stud.ntnu.no/~olekaam/thesis.pdf  from 1 August 2023 (Pending Review).

— Ole Kr. Aamot

Categorized as Node