how to make api server and call an api from node.js

making server for api interface

var sys = require("sys"),
    http = require("http"),
    url = require("url");

http.createServer(function(request, responsehttp) {
	responsehttp.writeHead(200, {"Content-Type": "text/html"});
	var url_parts = url.parse(request.url, true);
	var query = url_parts.query;
	var msg={
		'message':'your request is sent to sms server and you will get notified when request completed.'


to call an api from node.js

var smsclient=http.createClient(config.port,;
	var request=smsclient.request('get','/index.php?msg=hello world',config);
	request.on('response', function(response){
		var result = "";
		response.on('data', function(chunk){
			result += chunk;
		response.on('end', function(){
			console.log("result" + result);
var http = require('http');

http.createServer(function (req, res) {
    console.log('request received');
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('_testcb(\'{"message": "Hello world!"}\')');
$(document).ready(function() {
        url: '',
        dataType: "jsonp",
        jsonpCallback: "_testcb",
        cache: false,
        timeout: 5000,
        success: function(data) {
        error: function(jqXHR, textStatus, errorThrown) {
            alert('error ' + textStatus + " " + errorThrown);


Ref :



About rahul23134654

Hi, I am Rahul Meha , B.E. in (I.T.)
This entry was posted in Node.js. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s