App Engine doesn't read a file

40 views
Skip to first unread message

Giancarlo C.

unread,
Jan 15, 2018, 7:26:28 PM1/15/18
to Google App Engine
Hi everybody, I'm new in this kind of platform (cloud) and I have a problem with App Engine.

I have the following project structure in App Engine:

- Root
  - nodejs-docs-samples
  - src
    - be-nodejs-piloto
       - node_modules
       - api.js (api post uri)
       - app.js (main)
       - app.yaml
       - datastore-quickstart.json
       - package-lock.json
       - package.json
    - vibrant-tree-191664


app.yaml (content)
runtime: nodejs
env: flex

manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

api.js (content)
'use strict';

// Load libs.
var express  = require('express');
var router   = express.Router();
var path = require('path');

const Datastore = require('@google-cloud/datastore'); // Imports the Google Cloud client lib

// Your Google Cloud Platform project ID
const projectId   = 'datastore-quickstart-191515';
const keyFilename = '/home/testcloud99/src/be-nodejs-piloto/datastore-quickstart-5672f2cde8ca.json';

console.log('keyFilename:' + keyFilename);

// Creates a client
const datastore = new Datastore({
    projectId: projectId,
    keyFilename: keyFilename
  });


router.route('/api/piloto')

    .post(function (req, res)
    {
    console.log('method: POST');

        // Read params
        var pMsgId   = req.body.msgId;

        const query = datastore.createQuery('MyEntity');
        query.filter('msgId', '=', pMsgId);

        // exec query
        datastore
            .runQuery(query)
            .then(results => {

                //OK
                return res.status(200).jsonp({
                    "piloto":
                    {
                        "code" : 0,
                        "desc" : "ok",
                    }
                });

        })
        .catch(err => {
            console.error('ERROR:', err);
            return res.status(200).jsonp({
                "piloto":
                {
                    "code" : 1,
                    "desc" : "error",
                    "errorMessage" : err.message
                }
                });
        });

    });

module.exports = router;

So, when I send a POST message (using soapUI), I get this response:

{"piloto": {
   "code": 1,
   "desc": "error",
   "errorMessage": "ENOENT: no such file or directory, open '/home/megagecs/src/be-nodejs-piloto/datastore-quickstart-5672f2cde8ca.json'"
}}

I guess App Engine isn't recognizing that JSON file but I don't know why. Any kind of configuration that should be done?

Hope you can help me.

Regards.




George (Cloud Platform Support)

unread,
Jan 15, 2018, 11:38:11 PM1/15/18
to Google App Engine
Hello Giancarlo, 

Did you deploy your app? Do you test it using the local server? 

You seem to try using the local system in the app engine standard environment, which is not possible. 

This group is meant for general questions and voicing of opinions. For coding-related issues you are at an advantage if you post your questions on dedicated forums, such as stackoverflow, where competent and enthusiastic programmers are ready to help. 
Reply all
Reply to author
Forward
0 new messages