Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs & Express: How to send multiple Json variable from server to Client through response.send()

I am developing an nodejs search application for itunes-search and searching some software information from my local database with express framework. The search module returns information like software name, music name through a single json variable. But now I also need Music artist details/ Software company name through another different json variable. I can simply return the song details with the bellowed code. In client sides:

$scope.search_music_data = function(data)
{
  var data="Hamdoon Soft";//Search my favourite artist name or band name
    $http({'method' : 'post', url: '/search', data: {'search_item' : data}}).
    success(function(data){ 
        $scope.artist_name = data; 
    }).
    error(function(data){ 
    })
    $scope.check = true;
}

Bellowed codes are in server sides:

In route.js

app.post('/search', search.search_music);

In search_music function currently this code is working:

ItemName="calculated data Json Data"
var response.send(ItemName);

But I also need send another calculated data like

  ItemName="calculated data Json Data"
  ArtistName="calculated data Json Data"
  var response.send(ItemName, ArtistName);

Or ItemName="calculated data Json Data" SoftWareCompnayName="calculated data Json Data" var response.send(ItemName, SoftWareCompnayName); Is it possible?I will really appreciate him/her if he/she can help me.

like image 834
Muhammad Ashikuzzaman Avatar asked Jun 21 '15 12:06

Muhammad Ashikuzzaman


People also ask

What is NodeJS used for?

It is used for server-side programming, and primarily deployed for non-blocking, event-driven servers, such as traditional web sites and back-end API services, but was originally designed with real-time, push-based architectures in mind.

Is NodeJS is a programming language?

In a word: no. Node. js is not a programming language. Rather, it's a runtime environment that's used to run JavaScript outside the browser.

Is NodeJS frontend or backend?

Node. js is sometimes misunderstood by developers as a backend framework that is exclusively used to construct servers. This is not the case; Node. js can be used on the frontend as well as the backend.

Is NodeJS better than Java?

Java dominates enterprise computing applications, whereas, Node. js allows you to write both client and server programs using Javascript. Considering the ease of development, Node. js is better, but from application performance and security point of view, Java is the best.


1 Answers

Use this in server side code. I think this will help you. This is the example of multiple value sent from server to client.

res.send({artist: artist_details, music: music_details});

In client side :

you can access it data.artist & data.music from angular controller.

like image 151
Bilash Avatar answered Oct 13 '22 22:10

Bilash