Nightmare JS not working - javascript

I know the title of the question looks very vague! But that's there's to it.
I installed nodejs on my production server, which had phantomjs working properly, then I installed nightmare via npm install nightmare, I can see it in node_modules, I tried the example listed by the developers on github:
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true })
nightmare
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('#uh-search-button')
.wait('#main')
.evaluate(function () {
return document.querySelector('#main .searchCenterMiddle li a').href
})
.end()
.then(function (result) {
console.log(result)
})
Nothing happened, the script did not output anything, I simplified the script to a simple single goto, for a page on my server, the page was never called when I ran the script via node file.js
I have CentOS 6.7, phantomjs 1.1
I also tested it on a fresh CentOS 7 installation with latest version of phantomjs, same thing.
Am I missing some kind of prerequisite or something? How do I debug the issue since node script.js is not giving any output
UPDATE: Apparently the problem is, electron, which is used by nightmare 'instead of phantomjs' requires a graphical enviroment, which is why it fails to run in my enviroment.

New version of Nightmare requires electron, Not PhantomsJs. Make sure electron command is in your $PATH variable.
Install Electron
npm i -g electron-prebuilt
To debug:
DEBUG=nightmare* node script.js

Look at this Dockerfile: https://github.com/aheuermann/docker-electron/blob/master/7/Dockerfile
It s the minimal libs you need. And to start you script:
Xvfb -ac -screen scrn 1280x2000x24 :9.0 &
export DISPLAY=:9.0
DEBUG=* node src/index.js
Electron based app should no more crash

You can also try to set electron in the background without actually showing any GUI. You check if this works:
var nightmare = Nightmare({ show: false});

Related

Vue JS dev server doesn't work in Atom

I started my website project in Visual Studio Code and it worked fine for days. I found out about Atom and decided to move over to it. Somehow whenever I start the dev server in Atom, each Vue component spits out:
Console output (pastebin)
"Error: "extract-text-webpack-plugin" loader is used without the corresponding
plugin"
and the webpage only renders
Cannot GET /
The dev server starts fine in Visual Studio Code but not in Atom
I had the same problem with running npm run dev from CMD on Win7.
I dont know, as I did not require this plugin anywhere explicitly and when I started this error did not occure to me.
As i also started to get this error and I already tried setting NODE_ENV=development provided by this issue report from the official repo, I tried playing around.
Finally i ended up editing the webpack.dev.conf.js adding this specific plugin to the plugins key as follows:
// File header with other Imports
var utils = require('./utils')
// ...
var ExtractTextPlugin = require('extract-text-webpack-plugin')
// Then in Module definition
module.exports = merge(baseWebpackConfig, {
// ... other keys for module
plugins: [
// .. other plugins
// .. I copied this line from the webpack.prod.conf.js
new ExtractTextPlugin({
filename: utils.assetsPath('css/[name].[contenthash].css')
}),
Well there might be better and more beautiful solutions.
This is just the one that seems to fix it for me.
As I am new to VueJs and I am only using the dev server at the moment with autoreload, other answeres might be bit more polished.

Rendered HTML output using nodejs

We have a requirement to load the input HTML string into browser kind of environment, run the html (which should internally run all the inline scripts i.e there are a few ajax calls) and then provide the rendered HTML as output.
Is this possible with node?
Is there any node module which we can use for this purpose.
Please help in this regard.
Sound like you looking for headless browser for NodeJS. see a list here http://github.com/dhamaniasad/HeadlessBrowsers
This is example from CasperJS
You can install as Node module
npm install -g casperjs
And
var casper = require('casper').create();
casper.start('http://www.google.fr/', function() {
this.echo(this.getHTML());
});
casper.run();
Run
casperjs app.js
For NODEJS runtime
Try Nightmare
Install
npm install nightmare
code
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: false });
nightmare.goto("http://www.google.com")
.evaluate(function(){
return document.body.outerHTML;
})
.end()
.then(function (result) {
console.log(result)
})
Run
nodejs app.js

NW.js - PouchDB - Unable to use PouchDB via require() in node webkit

I am new to pouchdb and nw.js and may be this question is a little bit too simple, (sorry for my ignorance).
I am trying to to use pouchdb in a nw.js project via require() but with no luck.
According to the documentation for the pouchdb setup , under Node.js section, I dit it exactly as it says with no success.
After that I installed leveldown component into the project, and I have followed the following instructions under https://github.com/nolanlawson/pouchdb-nw github project.
So, at this point, I have already done the following:
nw-gyp configure --target=0.12.3 / in the node_modules/leveldown directory
nw-gyp build
Then, according to pouchdb.com/guides/databases.html I have:
var PouchDB = require('pouchdb');
var db = new PouchDB('kittens');
but again with no luck. In addition, by running the following:
db.info().then(function (info) {console.log(info); });
getting no response.
Note: If just include this <script src="../node_modules/pouchdb/dist/pouchdb.min.js"></script>
in the index.html file, everything works like a charm.
nw.js version: 0.12.3 /
pouchdb version: 5.2.1
What am I missing?
Did you try the demo? https://github.com/nolanlawson/pouchdb-nw-hello-world There are quite a few steps to install PouchDB correctly in NW.JS.
Edit: oh wait, yes, you did see the demo already. Maybe the issue is that LevelDOWN is incompatible with your version of NW? In my demo I was using an older version of NW than you.
Yet another option is to use the websql adapter inside of Node, which should give you similar performance to LevelDB while possibly being easier to compile than LevelDOWN. If all else fails, I'd recommend filing an issue on the LevelDOWN repo; they have tons of issues related to building for X version of Node on Y architecture on Z operating system, so your combination of XYZ might be a unique one.
Finally I found a working solution to my problem.
The work-around is as follows:
1) I updated pouchDB to 5.3.0
npm update pouchdb --save
2) Then navigate to node_modules/leveldown
cd node_modules/leveldown
3) configure gyp with nw.js target version
sudo nw-gyp configure --target=0.12.3
4) Build again the nw gyp
nw-gyp build
5) And then in my javascript module file
var PouchDB = require('pouchdb');
var arincPouchDB = new PouchDB('./db/arincAirports'); // new pouch db for node without adapter // means you get leveldb adapter in this case.
var jsonData = require("../datasrc/output/data.json");
arincPouchDB.bulkDocs(jsonData);
arincPouchDB.info().then(function (info) {
console.log(info);
});
6) And the console says...
Objectadapter: "leveldb"
auto_compaction: false
backend_adapter:"LevelDOWN"
db_name: "./db/arincAirports"doc_count: 12
update_seq: 12
__proto__: Object...
Note: If you try to use pouchDB from a script tag in your html file, and at the same time you have to use it in a javascript function, that will be exported via module exports e.g
exports.pouchDBFunction = new pouchDBFunction();
and to use this exported function in another javascript file,
like this
var json2PouchDB = require("./js/pouchDBFunction.js");
json2PouchDB.pouchDBFunction;
will not work and you will get the error pouchdb is not defined. That's why you need to have pouchDB via require() function.
Hope this workaround helps...

Socket.configure Undefined is not a function error

Note: I am using Mac OS 10.10 Yosemite
Important Note: None of the other questions and answers have worked for me.
I am following a tutorial which will have it so that I could have a multiplayer game. There is a file, which I have to download, which has a game.js file that I need to add this code into:
Note: I correctly downloaded socket.io in the correct directory.
var util = require("util"),
io = require("socket.io").listen(80);
var socket,
players;
function init() {
players = [];
socket = io.listen(8000);
socket.configure(function() {
socket.set("transports", ["websocket"]);
socket.set("log level", 2);
});
};
init();
But when I run node game.js, I get an error that looks like this:
Note: The Robhawks-mozzilla-festival-92336f2 folder is the folder that has all of the files in it
Why is the socket.configure messing up? Also, how can I fix it?
.configure() was removed when socket.io went to version 1.0. I'm guessing that the tutorial you're following is using an older version (0.9), but you have installed 1.0.
It would be best to move your code base to 1.0, as it's the latest. Configuration should be done as part of the server initialization:
var socket = require('socket.io')({
transports : [ 'websocket' ],
...
});
More info here.
However, since you're following a tutorial it may be easier to first get things up and running using the older version of socket.io, and once you have familiarized yourself with it, move to 1.0. In that case, install the older version:
$ npm install socket.io#0.9
Looging socket.io v1.0 log-level option is removed. Thus for logging one has to start program using debug module.
install debug: npm install debug -S
then run the program: DEBUG=* node entry_file.js

Warning 'The API interface has changed' when running Karma on grunt

When running karma from a grunt task I get the following warning:
Running "karma:unit" (karma) task
Warning: The api interface has changed. Please use
server = new Server(config, [done])
server.start()
instead. Use --force to continue.
Aborted due to warnings.
I have tested running karma with my configuration, both using the 'run' and 'start' karma commands and they seem to work fine.
Using grunt --force can complete the task, but it completes with warnings.
This are the versions that I'm currently using:
Karma 0.13.0
Grunt 0.4.5
grunt-cli 0.1.13
node.js 0.12.7
npm 2.11.3
The project was generated using yeoman (1.4.7) but I have the same problem using Karma in a separate project with just jasmine, karma and Grunt (also tested it with Gulp).
I have searched for the warning message but found nothing. I don't know if this is the expected behavior or if there is another way of completing the tasks without warnings.
They changed with new version here:
https://github.com/karma-runner/karma/blob/master/CHANGELOG.md#breaking-changes
var Server = require('karma').Server;
var config = {
configFile: path.join(__dirname, '/../karma.conf.js'),
singleRun: singleRun,
autoWatch: !singleRun
};
var server = new Server(config, done)
server.start()
If you are using the grunt-karma plugin to start the Karma tests from Grunt, you need to update the grunt-karma dependency in your package.json file to 0.12.0:
"devDependencies": {
...
"grunt-karma": "~0.12.0",
...
}
Version 0.12.0 of grunt-karma was released earlier today, and it uses the new API: https://github.com/karma-runner/grunt-karma/releases
I am using Gulp and I had to either setup my test task as follows:
var Server = require('karma').Server;
gulp.task('test', function (done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
or roll the karma version back to 0.10.0 to get it working. At this time there is not pull request on gulp-karma to change how this works, but not sure if there will be a change in the future.
Here is a helpful example that was updated after the Karma API change: https://github.com/karma-runner/gulp-karma
If you're using Yeoman's generator-angular like I was, you'll need to switch it out in your grunt-karma.js file.
Replace var server = require(‘karma’).server;
with var Server = require('karma').Server;
and then at the bottom of the file in the else block instead of server.start(config, done);
you'll find server.start(data, finished.bind(done));
just put var server = new Server(data, finished.bind(done)); right above it and it should work fine.

Categories

Resources