0

This is my app.js

var express = require('express');
var app = express();
var port = process.env.PORT || 8080;

var bodyParser = require('body-parser');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies

app.post('/coords', function(req, res) {

    var lat         = req.body.lat,
        lon         = req.body.lon;**strong text**

    res.send("DATA / Latitud: "+ lat +" - Longitud: "+ lon);

});

// start the server
app.listen(port);
console.log('Server start! at http://localhost:' + port);

I send 2 vars to my webservice every x seconds. I would like to pass the post data "lat" and "lon" to the client (index.html)

Ruben
  • 144
  • 8

2 Answers2

2

What is your Client ? are you using angular js ? If so read about Services,controller,$http, data binding and so on and use Json It will be more easy for you

app.post('/coords', function(req, res) {

var lat         = req.body.lat,
    lon         = req.body.lon;**strong text**

res.json({"Latitud":lat,"Longitud":lon});

 });
GroundIns
  • 541
  • 1
  • 5
  • 11
  • Thanks, my project is a real time position, i have a app mobile sending every x time post coordinates and more data to a web service. I need to get those post data and print in my index.html. What is the best way to do that?? – Ruben Dec 03 '15 at 12:54
0

Try below piece of code,

res.render('index.html', { lat: req.body.lat,lon:req.body.lon });
//instead res.send
Ajith Pai
  • 34
  • 5