Google Virtual Features Connecting your data warehouse locally with features

I launched the local Datastore emulator and although I wrote and tested GCF with a remote instance of Datastore (not emulated). Now I am trying to use a locally running instance of Datastore for testing, but all requests are still routed to the cloud-based instance of Datastore.

Here is the code

const db = require("@google-cloud/datastore")();

exports.signUp = (req, res) => {
    if(!req.body.firstName || !req.body.lastName || !req.body.email) {
        res.status(400).send("Incorrect user data passed");
    } else {
        let key = db.key("User");
        console.log("KEY: ", key);
        db.insert({
            key: key,
            data: {
                firsName: req.body.firsName,
                lastName: req.body.lastName,
                email: req.body.email
            }
        }, (err, apiResponse) => {
            console.log(apiResponse);
            if(err) {
                res.status(400).json({
                    message: "Error occured during creation"
                });
            } else {
                res.status(200).json({
                    message: 'Created under ${apiResponse}'
                });
            }
        });
    }
};

I know about the apiEndpoint parameter ( link to documentation ) in the configuration object of the Datastore instance. But should it be passed explicitly in code? I believe there should be some environment variable that will tell the default configuration to search for the Datastore emulator, and then try to use the cloud.

+5

Source: https://habr.com/ru/post/1674132/


All Articles