Do I need to use WebSockets to interface node.js with PhantomJS? - node.js

I couldn't find it referenced in the documentation but since PhantomJs is now at 2.1, Is there a way to use a WebSocket to interface NodeJs and PhantomJs directly or am I better going with StdIn/StdOut?
I'd like to skip the step of spawning a webserver plus a fake webpage to catch the events like I've seen on many github. If I can I would avoid those ninja tricks.

You really don't need WebSockets or the Web Server module.
There are basically two ways to use PhantomJS from node.js:
Write a plain PhantomJS script and spawn a PhantomJS process that executes that script, but this doesn't provide easy interactivity
Interface with PhantomJS through the many available bridges so that you can mix PhantomJS code with node.js code:
phantom, node-phantom, nightmare (version <1.8 used PhantomJS, now it's Electron), Horseman, navit, phridge, node-phantom-simple, jquery.go.js, SpookyJS (wrapper around CasperJS, which is a wrapper around PhantomJS), Selenium-Webdriver (JavaScript bindings), webdriver.io (other JS bindings for Selenium), etc.

Related

make chrome extension using nodejs

Question Background
We are building Chrome Extension. and we need to get the python code in the process.
What i know
I know that python code can be imported using Node JS.
Node JS is used to create servers
Chrome extension is not building server, but making programs(maybe client?)
is it right?
Question
To achieve our goal
Do We need to create server with node js and communicate with chrome extension(using socket.io)?
Is there another way to apply node js in chrome extension?
Is there another way to get the python code into the extension?
Your Chromium web extension code necessarily must be pure client-side Javascript structured to run in the browser's extension environment. There's no support for nodejs or python in that environment; it's very constrained. Because cybercreeps.
You can use XmlHttpRequest or fetch operations in your extension code to access web services. Your extension manifest will need to grant permission to access your server.
You can meet your requirement by building and hosting a server for your extension to use. You can use nodejs and a framework like express and/or socket.io, or you can use python, python-socketio, and a framework like Flask or Django. If you build your server with python, it probably will perform better than a nodejs serves that spawns child processes to run python. It will definitely be easier to install, debug and maintain.

general question about reactJS, nodeJS and NPM

first, the "facts" that I know:
reactJS is frontend framework, after compiling it'll generate a bundle of html/js/css files that can be recognized by modern browsers, so the browser straightforward request the web host server for these static html files ;
nodeJS is a server-side environment, or sometimes people call it a backend framework, browsers don't understand nodeJS but have to request the web host server to interpret it and to send back the html response.
according to wiki, npm is a package manager for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js.
my question is:
is my understanding correct
why reactJS also using npm and includes node_module, does it have something to do with nodeJS
Javascript is the programming language used in both Node.js and in the browser, but that's about as far as the similarities goes. Node uses the V8 engine, which is the same running in the chrome browser.
Even though they use the same engine, they are quite different. They both have plenty of APIs - most notably, the browser has the DOM (which allows you to render stuff to the screen). In Node.js you do not have the DOM, but there are other APIs, for accessing the filesystem for instance.
Since both are running JavaScript, you can try to run the same program both in node and in the browser, but it will sometimes fail. React is a front-end framework which uses the DOM, so if you try to run React in node, it will crash because in Node there is no DOM (Node has no screen to render to). If you try to run a program suited for Node.js in the browser, it will crash if it uses some Node-specific API.
The confusing bit is that npm is a package manager for JavaScript, not necessarily node (even though node is in the name..). Therefore, we can use npm also for web applications. (If we do, we need to use a bundler like webpack though).
Some npm modules might work both in the browser and in node, but some will only work on one of them. If the npm module requires some platform-spcific API (DOM for the browser for example) then it will not work for the other platform.
Hope that clears things out! I understand that it's a bit of a mess..

Does node's exec call block meteor application?

I am building a meteor application that creates pdf files from a web page using phantomjs.
PhantomJS is called with node's child_process.exec function within a fiber using Meteor._wrapAsync. When I am using any url like google.com, it is working fine and the pdf is created.
The problem is, I want to capture a site served by the same meteor application at /invoicePDF. But during the execution of phantomjs the site apparently does not load, thus, it cannot load inside phantomjs, which makes finishing the call to phantomjs impossible.
The solution seemed to be to use Meteor.bindEnvironment instead of Meteor._wrapAsync. Unfortunately, I have know idea why.

JS library that provides simple utilities for browsers and the nodejs environment?

I'm looking for a javascript library that attempts to provide the same simple utilities in both the browser environment AND nodejs (iteration, mapping, maybe control-flow) so that code can more easily be re-used across server and client. I know you can hack out parts of any JS library (YUI, jQuery, ...) and get them to work in both environments, I'm just wondering if it's already been done or standardized.
The closest I've seen is this: https://github.com/kof/sharedjs
But it's incomplete and has some odd stuff. I'm wondering if there is something more polished before I fork and hack.
The underscore library was built to add more functional programming to jquery, things like mapping, and also templating.
Because it doesn't rely on the DOM (it leaves that to jquery) it functions well in node.
The RightJS link library has a server build link that has node.js in mind.
From the download page:
RightJS is also available as a server-side library. In this case it contains only the native JavaScript unit extensions and the Class, Observer, Options units along with all the non-DOM utility functions from the Util module.
Our server-side build follows the CommonJS principles and is ready for use with the node.js framework.
Node's GitHub wiki has a list of CommonJS-compatible modules which will run in Node and browsers.
Some of the other modules on that page may also run in a browser environment. For example, the excellent DateJS works fine in Node. (It is available as a NPM.)
Btw, RightJS is also available on NPM

Writing a Web Application in Haxe without Apache and PHP?

Haxe has Apache httpd modules and can compile to PHP code. These are 2 options I know to make a web application that runs on the server. You can start a http server with nekotools, but this is supposed to be used for development only.
Are there any more options?
I can always use the NekoVM from within a C or C++ program, running a web server or interfacing to FastCGI. Or compile to C++, using a FastCGI or web server library. But I want to hear about solutions that are actually used.
I have a VPS with nginx, so no mod_neko or mod_tora. PHP isn't a problem, but I'd rather wouldn't use it (for irrational reasons).
More correctly there is an Apache module for the nekoVM. (You do need necessarily haxe to produce neko binaries)
To your question:
As far as I know there is currently no possibility to use the C++ target for webserver application, but some people are playing arround with some stuff.
As you said, you could use PHP
mod_tora or mod_neko on a Apache setup. (Why not use Apache?)
OR: the probably most interessting thing for you be: Link 1 and Link 2 (neko as cgi / fastcgi)
hxNode uses node.js. Don't know if anybody uses hxNode, but node.js got some good press lately.
I'm continuing to keep hxNode up to date and expanding it with the node.js spec.
I'm using it for my own projects and debugging it as I come across stuff.
Currently, hxNode, has the node.js api defined in Haxe, this is the standard node.js asynchronous API. Also, I've started to recreate the Haxe standard API using this API, so for example, js.FileSystem has been implemented, this makes use of the fact that latest versions of node can call fs module syncronously.
Other things which I'm working on with this API, servlet's sitting on top, and mongo bindings based on chriskv's mongo native drivers.
bd

Resources