How to run JavaScript on the server - javascript

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.

Related

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

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

Is it possible to use node.js as a faster, more elegant, database enabled alternative to greasemonkey?

I was using Greasemonkey eariler in the week to automate some calls to a page to scrape some data from a website, this was awkward for two reasons:
It's GUI based instead of commandline based)
I had to store all persisted information in JSON, and not directly in a database.
Would it be possible, to use node.js as a Greasemonkey alternative since node.js can store records directly in a database, and won't be required visually load pages the way the Greasemonkey does?
Also I would think that node.js would be easier to work with since you don't have to re-deploy it's scripts to Firefox the way that you have to with GreaseMonkey, allowing you to easily use version control on separate scripting projects.
On the other hand using node.js to do GreaseMonkey's job might just be using a hammer to pound in a screw, so I thought I would check here to find out if I am mistaken.
On the other hand using node.js to do GreaseMonkey's job might just be using a hammer to pound in a screw
I would say that the opposite is true; I believe you're using Greasemonkey to do the job of a server-side processing library. Greasemonkey runs in the browser and is designed to modify your web experience by running scripts on the pages you visit.
Indeed, I believe Node.js would be very well suited to this task. With libraries like jsdom and node-jquery, you can easily do JavaScript parsing over the DOM. You may also wish to take a look at node.io, a "distributed data scraping and processing framework." Finally, you may look into non-Node (but still JavaScript) based tools, such as PhantomJS and CasperJS, which can do scraping, DOM manipulation, screenshots, and more.
The question is a bit of a non sequitur.
Greasemonkey is for clients to tweak their individual browsing experience, client-side.
Node.js is for developers to deliver applications to the masses (hopefully), server-side.
For scraping data, in an automatable way, use Node.js or some server-side library (Python works well).
For "Mashups" of webpages that you browse, use Greasemonkey.

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/

Which Java Web Framework allows Cross-Domain Javascripting (http proxy)?

So just a quick intro, I am starting to explore Vaadin, and it's absolutely perfect. Previously, I was juggling PHP, Perl, Ruby, and Jquery for designing rich client web application. It didn't work out too well, as I've burnt out from trying to fix cross browser issues (aka get-it-to-work-on-IE-damn-it), handling server-side, client-side, and building a robust communication between the two tier had lot of code not related to application logic....by the time I was burnt out, only tiny bit of application logic was implemented.
Vaadin seems like the answer to my problem as it only requires Java and built on top of GWT.
However, I am curious how I can incorporate Cross-Domain Javascripting ? Back in LAMP environment, I had a CGI proxy script that loaded external URL, and injected JS into the proxy-loaded page. I used the CGI proxy script, as it rendered Javascript of the external URL well. Is there a class or package for Java or a specific Java web framework similiar to Vaadin that makes this possible ?
Thank you.
If you want to avoid any kind of proxies, and thereby keep a full context on each 'side', then you should choose easyXDM. To see it in action try http://easyxdm.net/current/example/methods.html
This fully supports all browsers, and has a neat RPC interface that lets you call methods and pass data between the domains.
If you plan to support IE6/7 then you should also try the upcoming version.
Even though the current version is fast (when used with a dependency), this one is even faster - actually nearly as fast as postMessage in never browsers!
You can easily implement the functionality yourself.
a proxy for cross domain javascript is really straightfoward.
It's just creating a request equivalent to the ajax request you want and direct it to the other domain.
ExtJS has what they call a "ScriptTagProxy" which may or may not be of use to you...
Here's a few more links about this:
http://xant.us/ext-ux/examples/css-proxy/
http://www.extjs.com/forum/showthread.php?17691-Cross-domain-Ext.Ajax-Ext.data.Connection

Categories

Resources