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)

2 Answers 2

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});

 });
Sign up to request clarification or add additional context in comments.

1 Comment

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??
0

Try below piece of code,

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.