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....
Related
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.
I'm working with PDFKit to generate a PDF in the browser, and then send the blob data of that PDF to a new tab for the user to download. I really like PDFKit...it's pretty slick.
However, I'm running into an issue when I try and use the PDFDocument.image() function to "draw" an image file:
Uncaught TypeError: fs.readFileSync is not a function
I'm pretty familiar with Node, and so I recognized that method signature immediately - the browser doesn't have fs natively! I'm less familiar with Browserify, and opted to instead use the pre-built version of PDFKit to avoid having to integrate another dependency that I'm not even familiar with.
My only guess is that the developers of PDFKit haven't included a working fallback for using this particular feature in the browser without Browserify - would using Browserify even give me access to the fs module (again, never used it)? Is that my only option here? Am I missing a particular step required to get this feature working?
Currently I'm including the following JS files as dependencies for my generate_pdf.js file:
pdfkit.js
blob-stream.js
Is there a module that emulates fs that I also need? I'm not seeing that documented, but it's been a long day.
Well, there are some libraries (like this or this), but I would highly recommend to write your own fs.readFileSync.
Since you're not likely to access client's filesystem from the browser anyway, using some existing solution would imply adding an abstraction level, etc.
So, probably the simplest and the easiest solution would be to add
var fs = {
readFileSync: (path) => {
// magic
}
}
Why probably? Well...
If there are usages of many fs functions, you'd obviously want to do it with some library
Synchronous requests. I guess you're loading images from some url, so you'll have to use synchronous requests in the implementation of fs.readFileSync to achieve the desired result. It's not like a big deal, but you'll get warnings in console.
P.S. sorry, but there's a hight probability that you'll face more issues with that because it's much more common to create pdfs on the server-side. Wy not move to the backend? ;)
I've got a .cpp file that has a class and some functions that produce a desired output. However, our project is being written in HTML5/PHP. My question is, can I take input from the HTML source, use my C++ code to generate some output, and send it back to the HTML to be used for display on the website? I've tried using emscripten to change my code into a .js file but the file it produces is 80k+ lines of code and nobody wants to deal with that. Is there a way I can get this to work or am I doomed to having to rewrite my C++ code in js for this project?
So, as with any language you can use it to run a server side solution to which the client can connect. With C++ you would thus have to look at something like these frameworks. The downside to that is that it requires an internet connection and a special server installation.
On the html5/client side you're indeed right that you could use Emscripten. 80k+ lines of code doesn't really say much without knowing what the original code did and how long that one was. If it was significantly shorter then you should look into all the flags for Emscripten, because you might have included code that never gets triggered (or some of your code might have triggered the inclusion of a full file system emulation module, despite you not needing that). Do however understand that you would never edit the code generated by Emscripten directly! That's not how Emscripten is intended, nor is it advisable for the simple reason that the code isn't meant to be readable, nor sensible. The only thing the code should be is fast and runnable.
I recently integrated my error logging with getsentry.com. My problem now it that I had to generate a source map so basically anyone with a modern browser can now see my original code fully commented.
I'm looking for a way to allow access to the source map files to only specific ips and/or subnets with nodejs, since I'm using heroku.
I imagine it will involve using something like https://www.npmjs.org/package/express-ipfilter or https://www.npmjs.org/package/ip. But still trying to think of how to create a middle where to 'route' to the files and evaluate the ips
Follow on from this question:
I am working on a Python 2.4 app which will run on Windows XP. It needs to be able to download various resources from HTTP and it's got to work in all of our office locations which use "PAC" files to automatically select http proxies.
Thanks to somebody who responded to my previous question I managed to find a technique to execute Javascript from within Python, it's really easy:
js = win32com.client.Dispatch('MSScriptControl.ScriptControl')
js.Language = 'JavaScript'
js.AddCode('function foo(a,b) {return a;}' )
result = js.Run( "foo", "hello" )
But here comes the problem:
The PAC file references a number of functions such as shExpMatch and isPlainHostName - these are presumably provided for free by Microsoft Internet Explorer. If I simply run the PAC file in Widnows Scripting using the recipe above it will fail because these functions are not missing.
So what I need is a way to set up the environment exactly the same way that IE does. The obvious way is to somehow import the functions in the same way that IE does.
I found that Firefox contains a single JS file which includes these functions, I suppose I could try to run Firefox's JS on Microsoft's scripting-host, but that sounds like a risky idea. What I really want is to make the javascript environment 100% Microsoft standard without anything that can make my life harder.
Any suggestions?
PS. You can see an example of a PAC file on Wikipedia. Unfortunately I cannot publish ours... that would violate company security.
Are you able to download the PAC file from the remote host? I am asking because usually urllib in python uses static information for the proxy, retrieved from the registry.
However, if you are able to get that file, then I think you could be able to get also another file - and then your idea of using FF version could kick in.