Running a js code on the server - javascript

I have a third-party javascript code which communicates with their web server and which I want to run periodically on the server. I'm not that familiar with NodeJS so that's why I don't know exactly wether it'll help me or not, although I've read some articles about that topic. The task is run that script on the server exactly as it were in a browser on the client. Is it possible to do with NodeJS?

The task is run that script on the server exactly as it were in a browser on the client. Is it possible to do with NodeJS?
Very nearly, yes. What you're looking for is a "headless browser" with a JavaScript API and/or NodeJS module. Specific recommendations are not what SO is for, but that's the term to search for, and I'll note that both jQuery and Sizzle projects (closely related) use PhantomJS. (I haven't used it directly, just as a byproduct of contributing to projects that do.) It's not a NodeJS module (it has to run in its own process), but you can launch it from Node as a project and then interact with it.
Then you load whatever assets you need into the headless browser, including the JavaScript you need to run.
Needless to say, you need to really trust the source of any code you receive and run on your server. :-)

Related

Difference betweeb Wamp, node JS and express?

I come ask my question here not because i did't found the answer but rather because i don't understand them...
Currently I try to do a website with HTML / CSS and basic JS but I need a database
And when I see different tutos in YouTube or other I always see Express, node...
Yes, I already use NodeJs but not Express, I only know him by name
And i'm lost, and i didn't know what to do to use mySQL with JS
I know Javascript is a front-end language and with NodeJS we can use it in back-end but...
In this case, with mySQL, what's difference between Node, Express and Wamp ?
All answer that i have is : *"Some of them are servers but not really a server, but more or less a server"
Yes, i didn't understand !
So can you please explain me what's three of them ?
Wamp simulate a locale server
But express too... ?
And node JS don't need to use a server... ?
If i use expressJS with Wamp will it be the same on a VPS ?
Please I need an explanation
WAMP is an abbreviation for Windows+Apache+MySQL+PHP environment. It is also the name of a package that lets you easily install Apache, MySQL and PHP on a Windows machine. Apache is a powerful web server software, which you can still use in front of Node, but don't have to (as a beginner, ignoring Apache is fine). PHP is a serverside programming language, but you are already decided on using JavaScript/Node.js, so you don't need it. For your purposes, simply installing MySQL instead of WAMP makes more sense.
Node.js is a serverside runtime for JavaScript language. It is what lets you run your JavaScript code on a server computer, along with some essential libraries that extend JavaScript with functions that it does not have built-in, such as the ability to read files, or to accept incoming connections (like HTTP requests).
You could make a web server purely in Node.js, but it would be a lot of hard work. Express.js is a framework (basically, a big library) you can install that already does a lot of that hard work for you, letting you focus on writing your web application's logic and not have to write low-level code that would make up the guts of your web application.
In the same way, you could theoretically write your own code to communicate with MySQL, but the mysql library exists so you wouldn't have to.
So if you are making a serverside JavaScript web application, you would typically start with installing MySQL and Node.js, then use npm (Node.js package management tool) to install Express.js and mysql packages. Apache is optional, so don't worry about it now; PHP is entirely superfluous.

Is it possible to use a webapp to install and run third-party software on the user's local machine?

My situation.
My company wants me to develop a webapp that will run 3rd party software on our client's machines. Basically, we developed some features for that software that we want our users to be able to use. However, the original software is very technical and we want to develop a simplified user interface that only provides the features that we developed, without the extra complicated bells and whistles.
The design passed down to me has this UI hosted on a webserver, but the software installed locally on the user's machine. However, this web-based UI is supposed to be able to execute commands to this locally installed software. (The person who designed this system seems to think this is possible to do with Javascript but I'm 99% sure it is not).
Putting aside the fact that this design doesn't make any sense (why wouldn't you just install the software on the server and run it there?), am I correct in believing that this would only be possible if we wrote a desktop program that would grant our webapp access to the user's local computer, and that we would have to get our user's to install it? Also, am I correct in thinking that this would be a security risk to our customers?
EDIT
My question is not about how to prompt the user to install the 3rd party software. My question is about how to issue commands to that software from a webapp.
What is the application written in? JavaScript and HTML (HTML5)? Or is it an actual installed type of application?
Can you write JavaScript that tells the user machine to install? Yes
Can you make sure it actually works? No, because it is not your computer.
Microsoft did one-click. The user still has to make some decisions, but if they said yes, it installed. There are similar paradigms in Java. If you want the "easiest", an offline website works, but realize it is a pain to actually debug.
But, your app is already written, so I assume you just want a magical install on the users machine so they can use it.
As far as one version of "how to". See this
EDIT: Accessing desktop apps from a web app is possible, if the app has a command line way of running it (which you mention). I am not sure how to do it in JavaScript, but I would look at running a command line application. In .NET, you have Process objects that can wrap the command line to get something running. This means putting the executable on the server and running it from a folder. For security, make sure that folder is inaccessible from people browsing, esp. if the app can create a huge security hole. If this presents a problem, you can also set it up behind an API internally, so it is behind a firewall and only allow HTTP access to the API from the external website.
You will have to figure the adapter to send the correct parameters to the command line to run and get your answer. Hopefully this uses command out, so you can just grab the information. If it writes files, you have another hurdle to leap.
NOTE: Technically there are ways of running apps with a full GUI this way, but it requires a lot of creativity and I would look at rewriting the functionality personally.

How to run JavaScript as a server side script language on SourceForge.NET?

As I known, JavaScript is a client-side scripting language. But, some days ago, I have heared that JavaScript is a server-side script language.
I don't understand about it... To know it, I have search Google, and I known that Node.JS can be used as a server-side script language. I have run some script with Node.JS (on Windows XP) successfully.
So, I tried to run it with a real server... I have posted all script (which are written in Node.JS) into SourceForge.NET. But, I don't know how do run it?
Can you help me to answer: "Does SourceForge.NET supports Node.JS? If can, please show me how to run with this server?".
I tried to run it with SourceForge.NET for only fun.
Node.js is a means of running JavaScript programs. It is commonly used to write HTTP servers.
If you have written code to use Node.js then you need to run it with Node.js for it to work.
If you want to involve some other kind of server then you would have to proxy requests made to it onto Node.js (e.g. with Apache's ProxyPass directive)… but that typically eliminates the reasons that people choose to use Node.js in the first place.
If you want to use Node.js in production then you will usually need to be hosting your site on a VM or a dedicated server. Shared hosting won't usually give you enough access to run Node.js.

How to setup a web app which can handle local data without uploading the data? Use python

I have a small python program to help my colleagues to analyse some tsv data. The data is not big, usually below 20MB. I developed the GUI with PyQT. I want to change this desktop program to a web app so my colleagues don't have to upgrade the program every time I change it or fix a bug. They can just go to a website and use Chrome as the GUI.
So how do I do this? I spend most of my time developing desktop program and just know some basic web developing knowledges. I have read some framework such as flask and web2py, and know how to use HTML and Javascript to make buttons but no clue to achieve my purpose.
Can someone give me a practical way to do this?
It'd be better if the user don't have to upload the local data to the server. Maybe just download the python code from server then execute in Chrome. Is this possible?
Thanks.
No, you cannot run Python code in a web browser.[1] You'd have to port the core of your application to JavaScript to do it all locally.
Just do the upload. 20MB isn't all that much data, and if it's stored on the server then they can all look at each others' results, too.
[1] There are some tools that try to transpile Python to JavaScript: pyjs compiles directly, and Emscripten is an entire LLVM interpreter in JS that can run CPython itself. I wouldn't really recommend relying on these.
The whole point of a web application is that the GUI is written in HTML, CSS, and JavaScript, not Python. However, it talks to a web service, which can be written in Python.
For a well-written desktop app, the transition should be pretty easy. If you've already got a clean separation between the GUI part and the engine part of your code, the engine part will only need minor changes (and maybe stick it behind, e.g., a WSGI server). You will have to rewrite the GUI part for the web, but in a complex app, that should be the easy part.
However, many desktop GUI apps don't have such a clean separation. For example, if you have button handlers that directly do stuff to your model, there's really no way to make that work without duplicating the model on both sides (the Python web service and the JS client app) and synchronizing the two, which is a lot of work and leads to a bad experience. In that case, you have to decide between rewriting most of your app from scratch, or refactoring it to the point where you can web-service-ify it.
If you do choose to go the refactoring route, I'd consider adding a second local interface (maybe using the cmd module to build a CLI, or tkinter for an alternate GUI), because that's much easier to do. Once the same backend code can support your PyQt GUI and your cmd GUI, adding a web interface is much easier.
If I get your point correctly, you want
Web connection, so your python program updated on server, client get it before using it.
Data store on local to avoid upload big file.
You can write a python program to check a server location to get your latest program if needed. You need a url / server file for program version / created date/time information to determine if you need to update or not.
After get latest python program, then start this python program to run locally.
With this said, What you need is to update your program to add below features:
Access your server, to get latest version information
Check against current version to see if you need to download latest program
Download latest version and use that to run locally.
Does this solve your problem?

GWT server with get() and post() built on client end

This is more of a curiosity really, to see if some one has done anything similar, or if at all it is possible.
I'm working on a project that will get notification through external notifications. Now I could go about doing this by having notifications coming to my server and have a comet setup between my client and server.
BUT
I was wondering if I could write server logic into my client and listen out for notifications from external sources. Immediately one issue I see is, external sources would need callback URL etc, which I dont know if you could do from client side (unless one could use the IP address in that way).
As you can see it is more ideas and discussions if such a thing was possible, this is somewhat inspired by P2P models whereby you wouldn't be mediating things through your central server.
Thanks in advance!
GWT compiles (nearly) Java source into JavaScript, so compiled GWT apps can't do anything that traditional JavaScript running in the browser cannot do. The major advantage of bringing Java into the picture isn't automatic access to any/all JVM classes, but the ability to not only maintain Java sources, which tend to be easier to refactor and test as well as keep consistent with the server, and to compile that statically defined code into JavaScript, performing all kinds of optimizations at compile time that aren't possible for normal JavaScript.
So no, while you can have some code shared by the client (in a browser) and the server (running in a JVM), you can't run Tomcat/Jetty/etc in the browser just by using GWT to compile the java code into JS.
As you point out, even if this was possible, it would be difficult to get different clients to talk back and forth, without also requiring that the browsers can see and connect at will to one another. BitTorrent and Skype have different ways for facilitating this, and currently browsers do not allow anything like this - they are designed to make connections to other servers, not to allow connections to be made to them.
Push notifications from the web server to the browser are probably the best way forward, either through wrapping comet or the like, or through an existing GWT library like Atmosphere (see https://github.com/Atmosphere/atmosphere/tree/master/samples/gwt-demo for a demo).

Categories

Resources