{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • Edge/API Management /
avatar image
0
Question by Jared · Oct 23, 2017 at 03:18 PM · 264 Views Private Cloudnode.jsbaasnode

Node app fails

Altough this code works, from my local, as sson as I deploy it to Edge, it causes me issue,

Can somone help.

Thanks

Package.json

{
  "name": "baas",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": {
    "name": "XXX",
    "email": "xxxx@xxxxx.com"
  },
  "dependencies": {
    "body-parser": "^1.18.2",
    "cors": "^2.8.4",
    "express": "^4.16.2",
    "usergrid": "^2.0.0-rc.2"
  }
}


Code

var express = require('express');
var bodyParser = require('body-parser')
var UsergridClient = require('./node_modules/usergrid/lib/client')
var UsergridQuery = require('./node_modules/usergrid/lib/query')


// var cors =require('cors')
/*Set up Express environment and enable it to read and write JavaScript.*/
var app = express()
// app.all(cors())
app.use(bodyParser.json())


app.use(bodyParser.urlencoded({
  extended: true
}))


var config = require('./config');
// Initialize Usergrid

var Usergrid = new UsergridClient({
	'orgId' : config.organization,
	'appId' : config.application,
	'clientId' : config.clientId,
	'clientSecret' : config.clientSecret,
    "authMode": "UsergridAuth.AUTH_CLIENT_ID",
    "baseUrl": "https://baas-ug002sr.apigee.net",
     Url: "https://baas-address.apigee.net",
	logging : config.logging
});




/*Authenticate user*/
Usergrid.authenticateApp(function(err, usergridResponse) {
    if (usergridResponse.ok) {
        console.log('app is now authenticated')
    }
})


// GET /
var rootTemplate = {
	'employees' : {
		'href' : './employees'
	}
};


app.get('/', function(req, resp) {
	resp.jsonp(rootTemplate);
});


// GET /profiles


app.get('/profiles', function(req, res) {	
		getProfiles(req, res);
});


function getProfiles(req, res) {
	Usergrid.GET('/profile', function(error, usergridResponse) {
    if (error) {
      res.jsonp(500, {
        'error' : JSON.stringify(error)
      });
      return;
    }
    var entities = usergridResponse.entities;
    //console.log('entities: ' + JSON.stringify(entities, null, 2));
    var emps = entities.map( (emp) => { return { entity: emp.accountA }});
    res.jsonp(emps);
  });
}




app.post('/profile', function(req, res) {


 if (!req.is('json')) {
   res.jsonp(400, {
     error : 'Bad request'
   });
   return;
 }


  var payload = req.body;
  var entity = {
    type: 'restaurant',
    restaurant: payload.restaurant,
    cuisine: payload.cuisine
  }


  if ((entity.restaurant === undefined) || ( entity.cuisine === undefined) ) {
    res.jsonp(400, {
      error : 'Bad request'
    });
    return;
  }


  Usergrid.POST(entity, function(error, usergridResponse, entity) {
    // entity should now have a uuid property and be created
        res.send(201);
  });
});


// Listen for requests until the server is stopped
app.listen(process.env.PORT || 9000);
console.log('The server is running!');




Error

{
	"fault": {
		"faultstring": "Script node executed prematurely: syntax error\nsyntax error\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"
		}
	}
}
Comment
Add comment
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Close

3 Answers

  • Sort: 
avatar image
0

Answer by Dino   · Oct 23, 2017 at 07:12 PM

You might be experiencing a trireme incompatibility.

It's possible the usergrid2.0 JS client is not compatible with trireme.

In case you did not know, trireme is the host for nodejs apps in Apigee Edge. If you run a nodejs app within Apigee Edge, today, then you are using Trireme. It's a JS engine that runs within the JVM. You can learn more about it on the project's github homepage.

Trireme is pretty neat, but there are some npm modules that rely on v8 being the host, and those modules won't run within trireme. The v2.0 JS client for Usergrid has been refactored significantly from the original 0.10 version of the client. This refactoring may have introduced a new dependency on a module that is not compatible with trireme.

I've reproduced the problem you reported, so it's not just you.

The workaround is to use the usergrid v0.10.x version of the JS client . OR, just use the request module directly; usergrid is just an HTTP endpoint.

I'll investigate a little more to see if I can more narrowly pinpoint what the problem is.

Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Jared · Oct 23, 2017 at 07:14 PM

By the way,

How do I access the full path to where all the Modules are installed?

varUsergridClient=require('./node_modules/usergrid/lib/client')varUsergridQuery=require('./node_modules/usergrid/lib/query')

Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Jared · Oct 23, 2017 at 07:17 PM

@Dino Thank a lot, I will use request module for the time been

Thanks

Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

81 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to stream an api response body to client 9 Answers

node script error during high load conditions 1 Answer

How to callout to Node.js? 3 Answers

Hosted targets Apigee - How to retrieve query params in index.js 1 Answer

When pointing to a Node app, page doesn't load correctly without a trailing slash. 0 Answers

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges