loading native addons on client side - javascript

Is it possible to load native add-ons (written in C/C++ like in nodejs) from client side javascript using requireJS or some other module?
I am writing a nodejs + express app that serves an html file which loads javascript files. I am using requireJS and compiling these client-side js files into AMD module. I can load and call native methods from the nodejs server side js scripts and wondering if its possible to do the same from the client side js scripts.

No, you can't force the client to execute a native application via the browser like that. It would present a very large security hole that would allow any hacker to come along and execute arbitrary violent code on any client and this is strictly prevented. You can execute the C++ add-on on the server side via an API though, and that should solve most use cases.

RequireJS is not the driving factor in what you are trying to achieve. The capability to load native code is solely dependent on whether the JavaScript VM that runs your code allows it or not. If the VM does not allow it, RequireJS cannot add this capability.
You can do it in Node because Node allows it.
Browsers are much more restrictive as to what they allow. A JavaScript script executing in a web page won't generally be able to load native code because, as Chris Franklin explained, it is a security hole.
One way to get the functionality provided by a C or C++ library to run browser-side is to use something like Emscripten to compile the C or C++ code to JavaScript.

Related

Is it possible to design GUI with HTML+CSS+JavaScript but it will actually run python script?

I've built a very simple assistant app in python which can do very basic tasks like taking notes, reminding you, stopwatch, timer, web scrape for news feeds etc. tkinter seems confusing and looks oldish to me. On the other hand, css js seems much easier to design gui side and way more elegant looking. Is it possible to design a desktop gui app (may be with electron?) using HTML+CSS+JavaScript but it will run my old python codes?
I've been coding for only two months and i suck at it. Please excuse my newbiness.
TLDR: Simply, i want to make the gui side using HTML+CSS+JavaScript to take user input but then it will run python scripts and shows output in the gui app. Is it possible?
It can't be done, you'd have to make it like a web app (although with local webserver serving python responses)
EDIT:
if you don't mind running it in webbrowser, you can make quite easily webserver, that will evaluate your queries...
The popular form of Javascript or ES6 (which you are talking about) is designed to run in browser, so, the limitations are that it can only make calls via browser, i.e. it cannot directly interact with the OS like python's OS module. This means you will need a web-service in your computer that would run a specific python code and return you the responses, this requires a web-service/web-framework, preferably python's like Django, Flask which will run the python script for you because they can make OS calls on the server machine. I do think other non-python web-services are cacpable to do so, but of course, the natural preference would be 'Python-based services'.
Sidenote:
If the case was with Node.js(i.e. the server-side js) and not ES6(client-side browser-run) you would have an upperhand i.e. you could invoke python scripts on your server because node.js like the python-based web-servers do support os calls.
Kinda, but its real ugly. If you can host your data and whatnot the other approaches will work.
You have to build your project around nw.js. Essentially it is a Chromium build that adds local file system access back in. You can build an HTML+JS Front end and access a node.js backend running in the same thread. Via node you can shellout to call your python program, or run a local python web server.
I built a mapping app that allowed the user to select a local file, process it on the local machine with python and display the results in an interactive D3 app with geojson based layers of the UnitedStates. Since the data was proprietary I could not host it outside the company. Since I was not IT, I could not host it inside the company. nw.js allowed me to package everything into an installer and deploy to other people within the company as a standalone app.
See here for more information:
Official site: http://nwjs.io
Official documentation: http://docs.nwjs.io/
Introduction
NW.js is an app runtime based on Chromium and node.js. You can write native apps in HTML and JavaScript with NW.js. It also lets you call Node.js modules directly from the DOM and enables a new way of writing native applications with all Web technologies.
It was created in the Intel Open Source Technology Center.
Features
Apps written in modern HTML5, CSS3, JS and WebGL.
Complete supportfor Node.js APIs and all its third party modules.
Good performance: Node and WebKit run in the same thread: Function
calls are made straightforward; objects are in the same heap and
can just reference each other;
Easy to package and distribute apps. Available on Linux, Mac OS X
and Windows

Does node.js replace tomcat?

If I can build a server with node.js do I need tomcat?
Excuse me, I'm a pretty new to it and I'd like to understand this base concepts. Thank you so much!
No, you do not need Tomcat if you are using Node. You could run one or the other, or both at the same time as long as they are not trying to listen on the same port. Here's why.
Tomcat is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies.
Basically, this means that Tomcat is designed specifically to be a web server.
Node is a JavaScript runtime built on Chrome's V8 JavaScript engine.
Basically, this means that Node can take JavaScript code, optimize it, and give the code access to things that aren't normally exposed to JavaScript code that is run in a web browser, like direct access to the file system. JavaScript is similar to Python, lacking strict data typing, but unlike Python which is an interpreted language, Node reads JavaScript and turns it into machine code which does not require it to be interpreted before it is executed (so it can be much faster).
Node happens to be good for developing servers especially when using frameworks like Express, sort of like Rails for Ruby, or Flask for Python, but you can write anything you want, it doesn't have to be a server.

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.

jQuery - run perl script (all standalone)

I have script Perl and for the moment this script is called with a simple batch file.
To make this interface more attractive, I'm looking for a language for create a GUI.
My first idea is to use jQuery/jQuery UI.
Before starting to learn, I want to know if is it possible to run a script perl with jQuery(UI).
fyi, I haven't Web server all code is standalone.
Of course, I'm interested if you have an idea for another language.
Thank's for your help.
jQuery is a JavaScript library for use in web pages. The primary way for JavaScript in a web page to interact with a Perl program is through HTTP (typically by using the XMLHttpRequest object to make an HTTP request). The HTTP server is responsible for running the Perl code (e.g. through PSGI, FastCGI, mod_perl, CGI or having a server written in Perl in the first place).
Without a web server, it isn't possible for a typical environment.
(There are exceptions, but they usually involve the browser being driven by Perl using something like Selenium).

How to configure a javascript engine not to run the code if it contains IO or system setting related functions?

I just started using a javascript engine from Microsoft(of IE9?) for developing both desktop and browser applications. I'm looking for a javascript engine which you can configure so that it won't allow any script if it contains IO or system setting related functions.
Is there any one?
If yes, please let me know which and how to do that.For details. I must call non-compiled javascript string code from compiled code( C# or C++ or else).
I know that you can tweak the security settings in the v8 javascript engine! You should check out the embedders guide: http://code.google.com/apis/v8/embed.html#security + I don't think it has I/O and System facilities unless you explicitly implement this in the C++ embedding code... This is how http://nodejs.org has done it.

Categories

Resources