What are the other applications of javascript engine other than web browser - javascript

I was exploring javascript Engines and there types and came across this phrase (inside wiki article):
"Although there are several uses for a JavaScript engine, it is most commonly used in web browsers."
But above linked article has information and history related to its web browser application only. So, I searched a lot but could only able to find it's use in node.js for server side scripting. But, I am still curious to know if someone knows any other potential application of js-engine.
Thanks.

For, example, Node.js - JavaScript on a webserver.
Also there are solutions for different tasks, even AI and neuronetworks.

JavaScript is also commonly used for scripting.
For example you can use it in order to create routines for administration and data management in Mongo shell.
You can use JavaScript for advanced NGINX configuration scenarios.
Javascript can be used for game (Unity) and application development (UWP) etc

Related

Embedding other programs in an Electron app

I have recently begun working with JavaScript and have learned of the Electron framework. I am very interested in this framework (and the whole web technologies for desktop use concept). My programming capabilities could be best described as hobbyist. I have written a few small games and apps for my own use, and have a number of shell scripts to help me automate some of my workflow in Linux. My question is, is it possible to use an Electron app that is powered by a language other than JavaScript? For example, I have a bunch of Python scripts (and recently, some Haskell and F# ones too) to help me with my statistics, calculus, and accounting courses in school. I don't mind running a bunch of different scripts to do what I want but lately I've gotten the idea of potentially making some of them available for general distribution. But my scripts are, as I mentioned, written in several different languages, most of them functional languages and none of them in JavaScript. Is it possible to wrap these scripts into something like an Electron app? If not, does JavaScript have any features similar to a functional language? How would one go about creating a JavaScript library or framework to fullfil this need?
I am aware of platforms like SageMath and GNU Octave, but the whole point is to create something of my own.
I would appreciate any thoughts or suggestions. Thank you.
The short answer is there's no direct/easy way to do what you want.
But you have some options.
There's a Electron compiler, but it works only with Javascript based languages like TypeScript and CoffeeScript.
You can, of course, develop a local web application and communicate with your Electron UI using HTTP requests, here is an example using Python.
You can also use sockets for interprocess communication: https://www.npmjs.com/package/electron-ipc-socket
And you also has the option to just start a child process directly from your Electron Application.
Hope it helps and don't make you more confuse :)

Creating a Javascript local application(ran in browser)?

I'd like to write an application that would use both Javascript and HTML as for the user interface. The app wouldn't really need an internet connection but will need access to the user's local files.
My first thought was that this would be impossible in a browser due to the security restrictions on the access to local files.
My second thought was to try to use webkit directly from C++ and use Python instead of Javascript, but that seems rather complicated, and I feel like overkilling by using Qt.
My third thought was to use a signed Java applet to make all local accesses, but then I'm not too sure of this either.
Any suggestions on what I should do?
I'll admit that I know very little about this, but it sounds like what you're after is what XUL provides.
From the homepage:
XUL (XML User Interface Language) is Mozilla's XML-based language that lets you build feature-rich cross platform applications that can run connected or disconnected from the Internet.
...
Web developers already familiar with Dynamic HTML (DHTML) will learn XUL quickly and can start building applications right away.
Regarding filesystem access: https://developer.mozilla.org/en/Code_snippets/File_I//O
This article describes local file input/output in chrome JavaScript.
You access the file system using Mozilla XPCOM components. A list of resources and interfaces for local I/O is available for both Files and Streams at XUL Planet.
Because of my lack of familiarity, I'll leave it up to the community to decide whether or not this answer has merit.
EDIT: Making this answer a community wiki since I don't have much real information to offer.
It seems, 5 years after the question was asked, there is a framework to do exactly this: build cross platform desktop app with JavaScript, HTML, and CSS, and with access to local files, http://electron.atom.io/.
I have not used it myself, but it is recommended in other answers.
You can always install needed servers locally and access user's local files that way.
I have been using Server2Go and MAMP
You could - for example - use Cappuccino: It allows you to build Applications in Objective-J (a language written in JavaScript) and run them either in the browser or as a Desktop application with local file access .
Then there is Adobe AIR, which allows you to write apps in JavaScript/HTML and access the file system.
Or you could use the new File Access API: http://hacks.mozilla.org/2009/12/w3c-fileapi-in-firefox-3-6/ (it has big restrictions, though: HTML 5 File API)
JavaScript is a beautiful language! Please update this question with information on which route you choose.
If you're not a Microsoft basher and/or don't mind being bound to IE, a Hypertext Terminal Application (HTA) is another option. I once (long ago) create a complete and pretty large stand alone database-application using HTA.
Do you know PHP? I suggest you to install Wamp or phpTriad or something similar for Windows. That way you can reach to the local files. If it is Linux most of the *nix based operating systems have build in Apache and PHP..
Mozilla currently develops Chromeless, which seems to be able to do exactly what you want and has filesystem access

Is CouchDB an example of Server Side Javascript?

I looking at using Javascript server side and took a look at persevere/pintura but for a novice like me, I need more documentation and tutorials and CouchDB seems to have a lot of that but is it used as a server side js tool?
Kind Regards
Yes (seconding what #Pointy said above). The JavaScript in CouchDB does run server-side. :)
Beyond that, though, JavaScript in CouchDB can do far more than just map/reduce queries. It's also used for document validation, update handling (for processing XML POSTed to CouchDB for example), as well as HTML or other markup output from either a single JSON document (using _show) or from the results of a map/reduce query (using _list).
CouchDB does not, however, offer filesystem access or TCP/IP listeners as Node.js does. Right now, the JavaScript is focused on the "shipping and handling" for the database contents (things like validation, formatting, and querying).
If you're interested in looking into options for handling things that CouchDB doesn't do "internally" (image processing, sending e-mails, etc), you might checkout my reply about CouchApp architecture options.
CouchApp's are definitely a viable option for web apps. Coupling those with replication, it's hard to beat.
http://nodejs.org/ is a great example for server-side javascript. If you don't want to write your complete webapp on NodeJS you can trigger it via the node command.
CouchDB is a database with an interresting feature, it allows you to interact via a RestFull api making it ideally suited to access over the web, either in javascript or other client environments. If you are looking for a server-side javascript development environment, try Servoy. It allows full featured server-side application development in javascript including easy database access to all major databases.
Short Answer: Yes.
Longer Answer:
There is a Javascript Engine shipped with CouchDB, which is SpiderMonkey
(the very first engine, open source, written by Brendan Eich, creator of javascript)
CouchDB's View function is JavaScript function running server side that acts as the Map half of a map/reduce operation to construct view.
Then there is client side javascript API, which can be used to communicate with the REST layer to fetch/update documents, which is also where jQuery is used by CouchDB.
More on CouchDB's both server-side & client side javascript capability:
The default engine is capable of doing many features, while package availability is limited compared to Node.js. Kan.so can be considered "NPM for CouchDB, where some packages are server side.
For example, there are frameworks like duality that try to make use of both server side & client side javascript capability to reuse code for rendering with couchDB.
More on the engine:
(The selection of spider Monkey over v8 is because for couchDB's use case the map reduce is not v8 designed for. Also include packaging, multi-threading and also historical reason v8 did not exist that time when spiderMoney is chosen) see [the mailing list] and tweet2
There is even project to port the whole CouchDB to Node.js (i.e. instead of Erlang), Chesterfield
I am glad if someone can add how Erlang talk with the javscript engine.
Thanks for everyone's answer, this is an important thing to make clear for people like me messing up couchDB with some Node.js packages
No, CouchDB is a document-oriented database that can be queried and indexed in a MapReduce fashion using JavaScript. CouchDB also offers incremental replication with bi-directional conflict detection and resolution.
http://couchdb.apache.org/
CommonJS can be used for server side JavaScript, see here: http://www.commonjs.org/
NodeJS is another: http://nodejs.org/

JavaScript on the server-side like PHP

I'm now thinking to establish my server-side code in JavaScript, and begin to do all on it, but I want to know about its security and flexibility compared to PHP.
I want to know too, if it can be successfully used to develop things like forum boards, full web-sites and things like this, as PHP does.
Javascript is just now starting to get some presence on the server, with things like ServerJS and nodeJS, but right now, you would probably be best off using PHP for your server side code, and javascript for client-side beautification.
The question is very, very broad. Interpreting it as "can I use Javascript on the server":
Fundamentally, sure, Javascript is a very powerful language and so you can do development in it server-side just like you can client-side (and if you do client-side scripting as well, you get some definite reuse benefits using Javascript on the server).
For Apache systems, there's the v8cgi project (a FastCGI Javascript plug-in with connectors, using Google's freaky-fast V8 engine).
On Microsoft-based systems, IIS supports Javascript (JScript) on the server out of the box (I use that all the time), which has access to all of the ActiveX stuff (e.g., for talking to databases, dealing with the file system, etc.).
If your server framework is JVM-based, there's Rhino, which is Javascript for the Java platform and has access to all (or nearly all) of the libraries available for Java — e.g., a huge ecosystem of libraries and plug-ins.
Aside from v8cgi, there are a couple of other projects built on Google's V8 engine.
There's a place that does a full stack for you called chromeserver (I don't know what their backend is; I'm not going to infer from the name).
Paul mentioned ServerJS and NodeJS.
There's the whole CommonJS project.
Etc. etc. etc. There's quite a list on Wikipedia.
Arguing against, there's a very rich ecosystem built around PHP. Unless you're using something like Rhino for the Java platform or JScript on IIS (because of the ecosystems they leverage), you may find that you don't have nearly that ecosystem available to you when developing in Javascript for the server. I mean, if you're looking for pre-built forum or wiki software (for example), let's just say you can't swing a dead cat without finding one based on PHP, and the same cannot be said of Javascript on the server.
The way they are usually used, PHP and JavaScript run in entirely different worlds, and are not really comparable. (There is a server-side version of JavaScript but it's fair to say it's not especially widespread yet, and doesn't run on standard web hosting.)
The security issues you are going to encounter in JavaScript (on the browser) side are very different from what you have to look out for in PHP.
I want to know too, if it can be sucessfully used to develop things like forum boards, full web-sites and things like this, as PHP does.
No, not with client-side Javascript. For dynamic applications, you will always need some server-side language backing it, be it PHP or some other language like ASP, Python, Ruby, Perl....
To replace PHP with Javascript, you need server-side Javascript and there is a lot happening on that front. Mozilla’s Rhino runs Javascript atop the JVM and it seems Google is also working on its own server side Javascript framework. The most popular in-production implementations are:
Helma: Several active projects are using it, runs on Jetty & Rhino and lets developers leverage the power of JVM, has its own object-oriented MVC framework
Project Phobos: runs on Glassfish & Rhino and lets developers leverage the power of JVM, includes plug-ins for NetBeans and integrates with jMaki Web UI framework
JSSP: A very simple server side framework, a lot like classic ASP, JSP and PHP
Aptana’s Jaxer showed a lot of promise, especially by bringing the DOM to the server side, but the project seems dead now. From what I understand, node.js is not a server-side Javascript framework in the same sense as Helma and Phobos. Instead it can be used for writing event-driven servers in Javascript (for example: writing your own web server).
Yes, my site is written by node.js
Using websvr, it's Java style have filter and handlers, hosting on debian OS.
This is slightly off-topic, but it may actually get to the core of your question:
if you want to use only one language for web applications, you may wanna have a look at Haxe.
It is a cross-platform language, that (among other targets) compiles to JavaScript and PHP source as well as NekoVM bytecode. For server-side JavaScript, there are NodeJS bindings.
This way you are not bound to a specific platform. The neko and PHP APIs are largely compatible, so you can deploy on both platforms, having the option to choose neko's speed and persistency or PHP's ease of deployment. Please note however, the PHP output has a little overhead although common optimizers as eaccelerator will make this barely noticeable.
Haxe is significantly less forgiving than both JavaScript and PHP. This makes it harder to learn, but a much safer, robust and in the end more productive tool.
In a word: no. Javascript is a client-side language. In order to do the things that you are describing, you need a server-side language such as PHP.
EDIT: OK, technically it is possible to implement Javascript in other areas besides the browser, but this is not very common.
5 YEAR EDIT: Well, 5 years later, this answer obviously is not accurate, with the popularity of things like node.js. Let that be a testament to how quickly things can change!
PHP and JavaScript are two different languages that do two different things. One cannot replace the other. You are most likely going to use a combination of the two. JavaScript for client-side stuff. PHP for server-side stuff.

How to run JavaScript on the server

I'm writing an iPhone app that needs to interact with the Google Maps API, therefore I must user JavaScript (please correct me if I'm wrong) to access the results and the route created.
Since the JavaScript support in native iPhone apps is quite poor and slow, my idea was to ask a remote web server to do the job for me. That server would be running Apache and PHP.
So my question is, it possible to run JavaScript on the server side? And if possible, how would you do that?
Besides server-side Javascript, you could access Google Maps API from wrappers in other languages; for example, here is an open-source project that wraps the API for Python (it does so by generating and wrapping the needed Javascript) -- that may or may not help for your specific use case, of course (but similar issues apply to server-side JS).
After doing some research I found Aptana Jaxer, a open source software that allows you to run Ajax, HTML, JavaScript and DOM modification server-side. It's available in:
http://aptana.com/jaxer
In their website reads:
HTML, JavaScript, and CSS are all
native to Jaxer, as are
XMLHttpRequests, JSON, and DOM
scripting. And as a server it offers
access to databases, files, and
networking, as well as logging,
process management, scalability,
security, integration APIs, and
extensibility.
There's also a very nice screencast that will get you started in a minute: http://tv.aptana.com/videos/introduction-to-jaxer-10?ref=search&refId=jaxer
You can use javascript on a server, for a list of examples see this wikipedia article
Google Maps API v3 has support for iPhone web apps, and iPhone OS 3.0 has Google Maps support for native apps. Both are a bit bleeding-edge and not quite complete yet, as I write this.

Categories

Resources