App Engine JavaScript SDK


Welcome to App Engine for JavaScript! Deploy powerful JavaScript Web Applications on Google App Engine using the familiar tools and libraries professionals love. Run your code on Google's scalable infrastructure with persistent storage and robust cloud services.

This is a community project, not affiliated in any way with Google.

This SDK is part of the Nitro ecosystem of Web Application development resources. It tracks developments in the CommonJS group.

Design and Implementation

The SDK is powered by Rhino. The API is inspired by Python's design—which is often closer to JavaScript's conventions than Java's. All delete() methods are renamed to remove() to avoid keyword conflicts (a DELETE() alias is provided for transition, but may be deprecated).

Python names like this_is_a_name become thisIsAName in JavaScript. Consult the docs for full details.

Datastore

The Python ext/db API is supported, with tweaks for JavaScript ergonomics.

var db = require("google/appengine/ext/db");

var Category = db.Model("Category", {
    label: new db.StringProperty(),
    category: new db.ReferenceProperty({referenceClass: Category})
});

var c = new Category({keyName: "news", label: "News"});
c.put();
var key = ...;
var c1 = Category.get(key);
var c2 = Category.getByKeyName("news");
var categories = Category.all().limit(3).fetch();

Blobstore

form:

var blobstore = require("google/appengine/api/blobstore");

exports.GET = function(env) {
    return {data: {
        uploadURL: blobstore.createUploadUrl("/test")
    }}
}

<form action="{uploadURL}" method="POST" enctype="multipart/form-data">
    <p>
        <input type="file" name="file" />
    </p>
    <p>       
        <button type="submit">Upload</button>
    </p>
</form>

upload:

var blobstore = require("google/appengine/api/blobstore");

exports.GET = function(env) {
    return {data: {
        uploadURL: blobstore.createUploadUrl("/save")
    }}
}

save:

var blobstore = require("google/appengine/api/blobstore");

exports.POST = function(env) {
    var blobs = blobstore.getUploadedBlobs(env);

    return {
        status : 303,
        headers : {
            "Location": "/serve?key=" + blobs.file.toString()
        }
    };     
}

serve:

var blobstore = require("google/appengine/api/blobstore");

exports.GET = function(env) {
    var params = new Request(env).GET();
    return blobstore.serve(params.key, env);
}

URL Fetch

var fetch = require("google/appengine/api/urlfetch").fetch;

var response = fetch("https://appenginejs.org"),
    html = response.content.decodeToString("UTF-8");

Images

var images = require("google/appengine/api/images");
var i = images.resize(params.image.data, 640, 480);

Email

var EmailMessage = require("google/appengine/api/mail").EmailMessage;

new EmailMessage({
    sender: "[email protected]",
    to: "[email protected]",
    subject: "My email",
    body: template.render(params)
}).send();

Memcache

var memcache = require("google/appengine/api/memcache");

var fragment = memcache.get("fragment");
if (!fragment) {
    ...
    memcache.set("fragment", fragment);
}

Users

var users = require("google/appengine/api/users");

var user = users.getCurrentUser();

if (users.isCurrentUserAdmin()) {
    ...
}

var url = user.createLoginURL();

Task Queue

var taskqueue = require("google/appengine/api/labs/taskqueue");

taskqueue.add({url: "/worker", method: "GET", params: {par1: "hello", par2: "world"}});  

var task = new Task({url: "/worker", method: "GET", params: {par1: "hello", par2: "world"}});
task.add("customqueue");

Forms

var Article = require("article").Article,
    ModelForm = require("google/appengine/ext/db/forms").ModelForm,
    ArticleForm = ModelForm(Article);

    ...

var form = new ArticleForm(params, {instance: article});
    ...
    form.save();

Example

See example/ for basic usage. For advanced usage, check out the blog-gae example.

Component Status

Credits

Google App Engine

This is a community project, not affiliated in any way with Google.

is a service of Google, Inc. Copyright (c) 2009 , all rights reserved.

License

Copyright (c) 2009-2010 George Moschovitis, http://www.gmosx.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Fork me on GitHub