newbeeep newbeeep - 10 months ago 77
Node.js Question

How to use jsonp with node.js express

i'm trying to make Samsung Smart TV app with node.js .

In my project, i want to make my app communicating with server pc.

According to Many Web sites, i can do this with "jsonp".

Here is a client side code that i found.

<title>jsonp test</title>
<script src=""></script>
<script type="text/javascript">
console.log('select_link clicked');

function test(data){
return {"message":"ok"};

dataType: 'jsonp',
data: "data=yeah",
jsonp: 'callback',
url: '',
success: function(data) {
<div id="select_div"><a href="#" id="select_link">Test</a></div>

And, here is a server side code that i found.

app.get('/endpoint', function(req, res){
var obj = {};
obj.title = 'title'; = 'data';

console.log('params: ' + JSON.stringify(req.params));
console.log('body: ' + JSON.stringify(req.body));
console.log('query: ' + JSON.stringify(req.query));

res.send(req.query.callback + '('+ JSON.stringify(obj) + ');');

These codes are working on my pc(server pc), but when i open client page on others computer, it doesn't work.

Console just give me this log :


I want to use jsonp to handle cross-domain, but it doesn't work i think...

What can i do to fix this?

Please give me help!!

Answer Source

just use


you can go ExpressJS JSONP for more info