Script node executed prematurely when calling the api

Not applicable

Hi

I get the following error when trying to access the api which was working fine on friday.

{"fault":{"faultstring":"Script node executed prematurely: missing : after property id\n at module.js:439\n at module.js:474\n at module.js:356\n at module.js:312\n at module.js:497\n at startup (trireme.js:142)\n at trireme.js:923\n","detail":{"errorcode":"scripts.node.runtime.ScriptExitedError"}}}

Here is the node.js logs

[2015-04-20T05:58:41.460Z nodejs/stderr svr.98] [2015-04-20T05:58:41.564Z nodejs/stderr svr.45] *** Starting script [2015-04-20T05:58:41.570Z nodejs/stdout svr.45] [2015-04-20T05:58:41.570Z nodejs/stderr svr.45] [2015-04-20T05:58:41.573Z nodejs/stderr svr.45] *** missing : after property id at module.js:439 at module.js:474 at module.js:356 at module.js:312 at module.js:497 at startup (trireme.js:142) at trireme.js:923 [2015-04-20T05:58:41.573Z nodejs/stderr svr.45]

Any idea why I am getting this error suddenly?

Thanks

Solved Solved
0 4 1,534
1 ACCEPTED SOLUTION

Can you run your script locally please? (e.g. node app.js) the objective is not to run the script fully but just to see whether it will start successfully or not.

You might have a syntax error somewhere in your code - possibly a json object with an "id" property which wasn't separated with ":" char, i.e. { "id" : "12345"}

View solution in original post

4 REPLIES 4

Can you run your script locally please? (e.g. node app.js) the objective is not to run the script fully but just to see whether it will start successfully or not.

You might have a syntax error somewhere in your code - possibly a json object with an "id" property which wasn't separated with ":" char, i.e. { "id" : "12345"}

Yes, there was a syntax error. Thanks

Hi @v Balan, "which was working fine on friday" and "ScriptExitedError" > suggests your server script could have terminated for some reason - some unhandled errors or something,

In this case, you could undeploy and deploy your proxy to see if your server comes up - but this is just a workaround. you might have to check your code if there is any possibility for failures

Not applicable
/* same Error while executing this code. Please help me with this */

const express = require('express');
const bodyParser = require('body-parser');
const session = require('express-session');
const requestUrl = require('request');


const app = express();
const PORT = process.env.PORT || 9000;

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(session({
    secret: 'this-should-be-secure',
    resave: true,
    saveUninitialized: true,
    cookie: {}
}));
app.use(function (request, response, next) {
    response.header("Access-Control-Allow-Origin", "*");
    response.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();
});
app.get('/', function (request, response) {
    response.send('Hello world');
});
app.get('/posts', function (request, response) {
    const options = {
        uri: 'https://jsonplaceholder.typicode.com/posts',
        headers: {
            'User-Agent': 'Request-Promise'
        },
        json: true
    };
    requestUrl.get(options, function (err, ds) {
        if (err) {
            response.send(err);
        } else {
            response.send(ds);
        }
    })
});
app.get('/posts/:postsId', function (request, response) {
    const postsId = request.params.postsId;
    // console.log(postsId);
    requestUrl.get('https://jsonplaceholder.typicode.com/posts/' + postsId).then(function (postsresponse) {
        response.send(postsresponse);
    }).catch(function (err) {
        response.send(err);
    })
});
app.post('/posts', function (request, response) {
    const title = request.body.title;
    const comment = request.body.comment;
    const userId = request.body.userId;
    requestUrl.post('https://jsonplaceholder.typicode.com/posts', {
        method: 'POST',
        body: JSON.stringify({
            title: title,
            body: comment,
            userId: userId
        }),
        headers: {
            "Content-type": "application/json; charset=UTF-8"
        }
    }, function (err, ds) {
        if (err) {
            response.send(err);
        } else {
            response.send(ds.body);
        }
    })
});

app.listen(PORT, function () {
    console.log('The server is listening on port 9000');
});