Stress testing a JAvascript file which only runs in the browser - javascript

I need to run a Javascript file for a relatively long time(maybe about 5 weeks or so at one time), without it stopping or being interrupted. Currently the script is a client side script which connects to the server and receives data via Sockjs. There is no HTMl/GUI. There is only some computation.
I need to make sure the client always stays connected to the server all the time. I need to be able to run some script from the command line which is like forever.js. I have tried porting the javascript to node.js but it doesnt work. It only works in the browser. I have tried reading the file and doing an eval but none of it works. Are there any other options open for me? I have tried phantomJS but that doesnt work too. I have looked at How can I use a javascript library on the server side of a NodeJS app when it was designed to run on the client? and Load "Vanilla" Javascript Libraries into Node.js but I reapeatedly get SockJS is not defined. I guess the problem lies deep in the library and is not a simple fix.
Could anyone give me some pointers? What are my other options? Whats the best way to test a client javascript library which seems to work only on the browser?
This is the repo I am using :
https://github.com/sockjs/sockjs-client
It doesnt seems to be running on node. I tried to replace the script tag with require, and download the sock.js into a separate file and use it.

There are "headless" browser modules available. These produce a virtual browser environment that can be programatically controlled. The primary use of these is to do unit/integration testing of browser side code without actually running a browser:
Phantomjs
Slimerjs
These might fit your needs. You can create a nodejs script that will load the said code in a virtual browser page.

Related

Webserver Resources when using Node Driver

I am currently building a demo for a simple cordapp, and am trying to implement a simple webpage to show an example of interacting with the node. I am launching my nodes using the node driver, and have created custom API's as well as some custom HTML and JS. I am having issues getting changes made to my JS and HTML files to propagate through to being shown on the webserver - and while I know these files are stored with the node I can figure out the correct method to go about getting the node to update these files.
I have tried removing the build folder, rebuilding the project and then running my node driver script, with no luck. I have also tried simply copying the files into build/resources, but I this also doesnt seem to work and I am not sure if this is where nodes run using the node driver actually pull their web resources from. Is there anything I am missing here? Could anyone potentially point me in the direction of a better process to develop and test this? (rather than having to re run my node driver everytime I make a change to either my HTML or JS files)
Turns out the issue had nothing to do with the Corda side of things, but rather developing in chrome. Due to chromes caching for some reason old JS file were being used. Resolved by flushing the cache using Ctrl+Shift+R (See Disabling Chrome cache for website development)

Run PHP/Javascript/AJAX Application On Schedule/Cron?

I have an application that I need to deploy that is a mix of pure PHP, JavaScript, jQuery, and AJAX. It runs flawlessly on all machines when called in a browser. Unfortunately, I also need to deploy this application to a machine that won't be able to run a browser.
Just running the file using PHP will output the resulting file, but does not execute any of the Javascript.
What are my options to get this task running? The machine will have access to xampp, but not to a browser.
Edit: the application grabs data from MSSQL, uses Javascript to turn that data into charts, uses an AJAX call to save those files to disk, and then calls another PHP script to mail a copy of the resulting files.
It depends on what your exact Javascript needs are, but unfortunately, if your application truly depends on a browser (and can't be ported to something more appropriate for the constraint), you will need to "fake" the browser somehow. Here are a few options.
PhantomJS is basically a headless Webkit engine (think Chrome or Safari).
HtmlUnit for a Java based solution, supported/developed by Mozilla
Other rabbit holes (Wikipedia/Headless Browser)
NodeJS offers a non-browser, headless, Javascript specific option, but will require your code to be more robust and generic than many code bases initially are when originally coded for browsers.

running javascript plugins in node

I'm not sure if this is possible without some serious tweaking but is it possible to run javascript plugins server side with node...
more specifically
I would like to run the dymo javascript sdk from node (the printer is attached to the server)
that way any device can print from the server.
I have tried using https://github.com/tojocky/node-printer as a workaround however it doesnt work in my situation (works with my laserjet though)
I have tried just requiring the file that failed miserably.
if this is possible can you just point me in the right direction I have been searching the google and even been corresponding with dymo developers however I havent gotten much help from them.
so the simplest way to put it: Can you run clientside javascript plugins from server side? if not is there a way to write a middleware that will act as a bridge?
here is the plugin file(before I modify it more): http://irwinproject.com/jss/Dymo.js
its a bunch of craziness. I am trying to modify it to work as a module
UPDATE: I have gotten most of the functions running properly however I have hit a bit of a snag their sdk requires active x which I dont understand because I'm on a mac and it works
can someone explain to me how active x can function client side on a mac? (i thought that was windows only) and also is there anyway to implement the same framework(activex or other) through node
if I understand this correctly active x is used as an abstraction layer between javascript and hardware
You have to return your object or functions with module.exports, also try to verify you are requiring your file with . so node knows is a local module.
Check this SO post with a highly upvoted answer :
What is the purpose of Node.js module.exports and how do you use it?
module.exports is the object that's actually returned as the result of
a require call.
The exports variable is initially set to that same object (i.e. it's a
shorthand "alias"), so in the module code you would usually write
something like this....

Possible Autoit-like JavaScript macros?

The title says it all. Is there a way to write macros in JavaScript to achieve a similar functionality to that of Autoit? I just would want to manipulate files on my own computer (offline) and could easily do it with autoit, but since I am currently learning JavaScript -- plan to develop in Node.js -- I figure it wouldn't hurt to get the extra practice.
Thanks guys!
Use an application which supports JavaScript as a shell scripting language, such as the following:
JsRoboKey
PowershellJS
PowerChakra
RemoteNodeJS
JScript + WSH
JavaScript Shell Scripting with JSC
QtScript: QScriptEngine
Part I: How to Choose a JavaScript Engine for iOS and Android Development - OpenAphid-Engine
nodejs has a module which do autoit things --
nodejs install autoit
var au = require('autoit');
au.Init();
au.Run("notepad.exe");
au.WinWait("[Class:Notepad]");
au.Send("Hello, autoit & nodejs!");
NodeJS is a very powerfull platform, it is extensible and opensource.
There is no problem to run local scripts to do everything you need using JavaScript (see standard FileSystem library docs). You can also try to look in NPM(NodeJS package manager).
Assuming you have AutoIt installed (say in folder C:\AU3) and this folder in the PATH, you can add
extension '.AU3' to the PATHEXT environment variable, and create an AutoIt script called, say,
hello.au3 with just a silly line:
MsgBox(0, "Warning", "Hello, World!")
Now, simply typing the command 'hello' will execute the script, displaying the silly message in a modal message box.
Next, create an equally silly Node.js script, say, MyWarn.js - in the same folder:
var oCP = require("child_process");
console.log("Starting...");
var oNP = oCP.execSync("hello");
console.log("Done.");
Assuming Node is also in the PATH, try this command:
node MyWarn
So ... we get the benefits of Node (for its jit), and the benefits of AutoIt (for its GUI handling.)
The problem is getting the two to communicate. Personally, I use a RamDisk to pass small files...
Javascript can't write to a file on your local machine remotely.. Its almost the same as HTML in a view model.
It can however perform some executions of other scripts via AJAX for example. But thats on server again.
It might be worth a look to read on server && client side differences.
im not 100% sure but node might offer another outlet on this but it would still be server side.. Not locally.
The Server - This party is responsible for serving pages and handling the logic | Code behind.
The Client - This party requests pages from the Server, and displays them to the user. On most cases, the client is a web browser.
The User - The user uses the Client in order to surf the web, fill in forms, watch videos online, etc.

Writing to a System File Using Javascript

I'm working with an API with a feature that can only be accessed (easily) using Javascript, but I want to use the API to save a .txt file to my server. Is there any way to achieve this on a Mac OSX machine? I know that JS running in a browser is prohibited from doing this, so I guess this is really a two part question: (1) what's the simplest way to run a 10 line JS script on Mac OSX and (2) how would I write data to a txt file doing this?
You could go for a headless browser for example PhantomJS. I haven't used it, but it should run JS well.
The same restrictions apply though, no filesystem access from JS.
Unless you use something like the plugin framework in FF, in that case you have elevated rights for the scripts.
Besides that you could create a wrapper in php, perl or other language, and pass on the data from JS to them in an ajax call, and they write the txt for you.

Categories