The following code works on Local just fine, however throws a runtime exception when deployed on Apigee Edge. The modules in package.json are uploaded fine.
Steps
1. Created server.js on local
2. Created package.json using npm init
3. npm install --save all three packages on local. They install & package.json gets updated.
4. Run the App on local and it works fine. (When I post json object using postman, the data gets inserted in Baas)
5. Deployed the App on Edge using apigeetool deploynodeapp
6. Deployed with success and all modules (zip files), package.json & server.js are uploaded and deployed as target for edge proxy
7. When trying to post data on edge proxy it gives a runtime exception (below).
Am I missing a step here ? Please advise.
Thanks
Syd
Error
{
"fault": {
"faultstring": "Script node executed prematurely: TypeError: Cannot find function assign in object function Object() { [native code for Object.Object, arity=1] }\n.\nTypeError: Cannot find function assign in object function Object() { [native code for Object.Object, arity=1] }\n.\n at /organization/environment/api/node_modules/node-rest-client/lib/nrc-parser-manager.js:112\n at /organization/environment/api/node_modules/node-rest-client/lib/node-rest-client.js:10\n at /organization/environment/api/server.js:4\n at module.js:456\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"
}
}
}
server.js
var express = require('express');
var app = express();
var Client = require('node-rest-client').Client;
var httpClient = new Client();
var bodyParser = require("body-parser");
app.use(bodyParser.json());
app.get('/', function(request, response){
response.type('application/json');
response.send(JSON.stringify({message:'hello world', status:'200 OK'}));
});
app.post('/orders', function(request,response){
response.type('application/json');
var data = request.body
var args = {
data: {test:data} ,
headers: { "Content-Type": "application/json" }
};
httpClient.post("https://apibaas-trial.apigee.net/<myorg>/sandbox/orders", args, function (data, res){
console.log(res.statusCode);
});
response.send(JSON.stringify({message:'Data was created', status:'200 OK'}));
});
app.put('/update', function(request,response){
response.type('application/json');
response.send(JSON.stringify({message:'Data was updated', status:'200 OK'}));
});
app.delete('/delete', function(request,response){
response.type('application/json');
response.send(JSON.stringify({message:'Data was deleted', status:'200 OK'}));
});
var server = app.listen(9000, function(){
console.log('Node server is running..');
});
package.json
{
"name": "node2",
"version": "1.0.0",
"description": "my node server",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.2",
"express": "^4.16.2",
"node-rest-client": "^3.1.0"
}
}