Anand Kumar
Anand Kumar

Reputation: 66

nightmare DEBUG on Google app engine Standard Environment

I am running nightmare on Google app engine. I guess it is not working. So И wanted to add DEBUG=nightmare but it is failing on start.

This is my package.json

"scripts": {
    "preinstall": "apt-get update && apt-get install -y libfontconfig1 libgtk2.0-0 libgconf-2-4 libasound2 libxtst6 libxss1 libnss3 xvfb && npm install nightmare",
    "deploy": "gcloud app deploy",
    "start": "xvfb-run -a node app.js",
    "lint": "samples lint",
    "pretest": "npm run lint",
    "system-test": "samples test app",
    "test": "npm run system-test",
    "e2e-test": "samples test deploy"
  },
  "dependencies": {
    "express": "4.15.4",
    "nightmare": "2.10.0"
  }

This is the error

Application startup error:

[email protected] start /app

xvfb-run -a DEBUG=nightmare node app.js
/usr/bin/xvfb-run: 183: /usr/bin/xvfb-run: DEBUG=nightmare: not found npm ERR! file sh

Upvotes: 0

Views: 445

Answers (1)

J0nh1dd3n
J0nh1dd3n

Reputation: 171

Node.js is not supported on AppEngine Standard. So you might be running on Flex environment. I started with this [1]. See the package.json differences. I modified the package.json to match your case and tried nightmare in the app.js.

I could reproduce your case by replacing "start": "xvfb-run -a node app.js", on the package.json by:

xvfb-run -a DEBUG=nightmare node app.js 

The help page for the previous command shows:

-a        --auto-servernum          try to get a free server number, starting at
                                --server-num
-e FILE   --error-file=FILE         file used to store xauth errors and Xvfb
                                output (default: /dev/null)
-f FILE   --auth-file=FILE          file used to store auth cookie
                                (default: ./.Xauthority)
-h        --help                    display this usage message and exit
-n NUM    --server-num=NUM          server number to use (default: 99)
-l        --listen-tcp              enable TCP port listening in the X server
-p PROTO  --xauth-protocol=PROTO    X authority protocol name to use
                                (default: xauth command's default)
-s ARGS   --server-args=ARGS        arguments (other than server number and
                                "-nolisten tcp") to pass to the Xvfb server
                                (default: "-screen 0 640x480x8")

I can’t see anything about DEBUG... So you might want to do something like:

xvfb-run -e error.log  -a node app.js 

To save the errors, but I’m not sure.

I’m going to share my configuration.

I share it with you before running ‘sudo npm install’ and after:

I added:

"preinstall": "apt-get update && apt-get install -y libfontconfig1 libgtk2.0-0 libgconf-2-4 libasound2 libxtst6 libxss1 libnss3 xvfb && npm install nightmare",

And modified: "start": "node app.js", To: "start": "xvfb-run -a node app.js",

before:
{
  "name": "appengine-hello-world",
  "description": "Simple Hello World Node.js sample for Google App Engine Flexible Environment.",
  "version": "0.0.1",
  "private": true,
  "license": "Apache-2.0",
  "author": "Google Inc.",
  "repository": {
    "type": "git",
    "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
  },
  "engines": {
    "node": ">=4.3.2"
  },
  "scripts": {
    "preinstall": "apt-get update && apt-get install -y libfontconfig1 libgtk2.0-0 libgconf-2-4 libasound2 libxtst6 libxss1 libnss3 xvfb && npm install nightmare",
    "deploy": "gcloud app deploy",
    "start": "xvfb-run -a node app.js",
    "lint": "samples lint",
    "pretest": "npm run lint",
    "system-test": "samples test app",
    "test": "npm run system-test",
    "e2e-test": "samples test deploy"
  },
  "dependencies": {
    "express": "4.15.4"
  },
  "devDependencies": {
    "@google-cloud/nodejs-repo-tools": "1.4.17"
  },
  "cloud-repo-tools": {
    "test": {
      "app": {
        "msg": "Hello, world!"
      }
    },
    "requiresKeyFile": true,
    "requiresProjectId": true
  }
}

After ‘npm install’ the file auto updates to:

{
  "name": "appengine-hello-world",
  "description": "Simple Hello World Node.js sample for Google App Engine Flexible Environment.",
  "version": "0.0.1",
  "private": true,
  "license": "Apache-2.0",
  "author": "Google Inc.",
  "repository": {
    "type": "git",
    "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
  },
  "engines": {
    "node": ">=4.3.2"
  },
  "scripts": {
    "preinstall": "apt-get update && apt-get install -y libfontconfig1 libgtk2.0-0 libgconf-2-4 libasound2 libxtst6 libxss1 libnss3 xvfb && npm install nightmare",
    "deploy": "gcloud app deploy",
    "start": "xvfb-run -a node app.js",
    "lint": "samples lint",
    "pretest": "npm run lint",
    "system-test": "samples test app",
    "test": "npm run system-test",
    "e2e-test": "samples test deploy"
  },
  "dependencies": {
    "express": "4.15.4",
    "nightmare": "^2.10.0"
  },
  "devDependencies": {
    "@google-cloud/nodejs-repo-tools": "1.4.17"
  },
  "cloud-repo-tools": {
    "test": {
     "app": {
        "msg": "Hello, world!"
      }
    },
    "requiresKeyFile": true,
    "requiresProjectId": true
  }
}

I’m sharing a snippet js with nightmare:

'use strict';
// [START app]
const express = require('express');
const app = express();
const Nightmare = require('nightmare')
app.get('/', (req, res) => {
  Nightmare({show: false})
  .goto('https://google.com')
  .wait('body')
  .insert('input[aria-label="Search"]', 'node-nightmare github.com')
  .click('input[type="submit"]')
  .wait(1000)
  .wait('body')
  .evaluate(function() {
     // return $('a:contains("node-nightmare")').text();
     // res.status(200).send($('a:contains("node-
nightmare")').text()).end();
     console.log('EVALUATE');
  })
  .then(function(ret) {
     console.log('THEN');
     console.log(ret)
  });
  res.status(200).send('Hello, world!!!!!').end();
});
// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`App listening on port ${PORT}`);
  console.log('Press Ctrl+C to quit.'); 
});
// [END app]

You can run on local server with : npm start Or deploy to App Engine with gcloud app deploy

Hope it Helps!

[1] https://cloud.google.com/appengine/docs/flexible/nodejs/quickstart

Upvotes: 4

Related Questions