0

I'm using node-push server from here

I'm able to start the server successfully. Below is my config file

{
"webPort": 8000,

"mongodbUrl": "mongo URL",

"gcm": {
    "apiKey": "API KEY"
},

"apn": {
    "connection": {
        "gateway": "gateway.sandbox.push.apple.com",
        "cert": "/path/to/cert.pem",
        "key": "/path/to/key.pem"
    },
    "feedback": {
        "address": "feedback.sandbox.push.apple.com",
        "cert": "/path/to/cert.pem",
        "key": "/path/to/key.pem",
        "interval": 43200,
        "batchFeedback": true
    }
}

}

Below is my service

var express = require('express');
var bodyParser = require('body-parser');
var app = express();

app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.get('/sendTestGCM',function(request,response){
var querystring = require('querystring');
var http = require('http');//importing http

var registrationIds = [];
registrationIds.push('key here');
var gcm_android = querystring.stringify({//message to be sent
    "users": registrationIds,
    "android": {
        "data": {
            "message": "Test Message with Node-push server package"
        }
    },
    "type":"android"
});
var options = { //URL information 
        host: 'localhost',
        path: '/send',
        port: '8000',
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Content-Length': gcm_android.length
        }
};

var post_request = http.request(options,function(res){//Post Request
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
        console.log('Response: ' + chunk);
        console.log("status code"+res.statusCode);
        response.end(""+chunk);
    });
});
post_request.write(gcm_android);
post_request.end();
});
app.listen("port");

When I test this service it is throwing exception as "Error: No default engine was specified and no extension was provided.".

Anyone please suggest me reason for this.

Thanks In Advance.

Neeha
  • 727
  • 3
  • 9
  • 21

1 Answers1

1

Try to change your options object to:

var options = { //URL information 
        "host": "localhost",
        "path": "/send",
        "port": "8000",
        "method": "POST",
        "headers": {
            'Content-Type': 'application/json',
            'Content-Length': gcm_android.length
        }
};

the property name must be a (quoted) string in orde to be a JSON object. From this answer:

the JSON specification dictates the use of quotes in order for it to actually be JSON. If you don't use quotes, it may be a valid object literal in Javascript, but it is not JSON.

Community
  • 1
  • 1
Txugo
  • 5,008
  • 5
  • 33
  • 40