Nightmare.js not working as expected on Ubuntu Linux cloud server
Your issue is most likely described by https://github.com/segmentio/nightmare/issues/224
Nightmare uses Electron which requires an X display; since your server doesn't have a display, you can use Xvfb to provide a virtual one. Install xvfb, and run
xvfb-run node --harmony hello_nightmare.js
I'm just posting this for posterity.
Below is the bash script to install nightmarejs with node (4.2.4) on a clean Ubuntu Linux machine. I've tested this on a DigitalOcean droplet running 14.04.
apt-get -y update
apt-get -y upgrade
apt-get -y --force-yes install make unzip g++ libssl-dev git xvfb x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps clang libdbus-1-dev libgtk2.0-dev libnotify-dev libgnome-keyring-dev libgconf2-dev libasound2-dev libcap-dev libcups2-dev libxtst-dev libxss1 libnss3-dev gcc-multilib g++-multilib
mkdir src
cd src
wget https://nodejs.org/dist/v4.2.4/node-v4.2.4.tar.gz
tar xzf node-v4.2.4.tar.gz
cd node-v4.2.4
./configure
make -j2
make install
cd ..
mkdir nightmarejs
cd nightmarejs
npm -f init
npm install --save nightmare vo
Then you simply create the .js file (e.g. hello_nightmare.js) (in the same directory where nightmarejs is installed) and then run it using the command below (as already mentioned in @yoz's answer):
xvfb-run node --harmony hello_nightmare.js
I hope this helps.
Since electron requires X display you need to install all the following packages
sudo apt-get install -y xvfb x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps clang libdbus-1-dev libgtk2.0-dev libnotify-dev libgnome-keyring-dev libgconf2-dev libasound2-dev libcap-dev libcups2-dev libxtst-dev libxss1 libnss3-dev gcc-multilib g++-multilib
Tested in ubuntu server in aws ec2
and it worked
then run your script:
xvfb-run node --harmony script.js