question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

importing EE javascript api into another javascript script--and not through html

See original GitHub issue

Hey Folks. This is really more a question than an issue, but I though others might benefit. The javascript demos posted all have the js “application” accessing/importing the EE javascript api through the script tag <script src="/static/ee_api_js.js"></script>. I was wondering how to import this ee_api_js.js file directly into a javascript script–and avoiding the html? I did not see any demos that did that.

So say I want to execute the code below to download a url without going through html.

var mymod = require('/../javascript/ee_api_js');

var image = mymod.Image('srtm90_v4');
var path = image.getDownloadURL({
    'scale': 30,
    'crs': 'EPSG:4326',
    'region': '[[-120, 35], [-119, 35], [-119, 34], [-120, 34]]'
});
print(path);

But I get an error:

var image = mymod.Image('srtm90_v4');
                  ^
TypeError: mymod.Image is not a function

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
genacommented, Oct 27, 2017

For Node.js applications, you can try ee-runner. However, it mainly targets server-side and command-line apps and not web apps. For web apps, require() is still a relatively new feature, it may be better to still merge everything using something like Rollup or Webpack, to make sure it works with legacy browsers.

0reactions
donmccurdycommented, Sep 24, 2019

The Earth Engine JS library is now available on NPM. See:

var ee = require('@google/earthengine');
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I include a JavaScript file in another JavaScript file?
You simply have to write import cond from 'cond.js'; to load a macro named cond from a file cond.js . So you don't...
Read more >
How to include a JavaScript file in another JavaScript file?
Takeaway: An ES6 module is a JS file that can export its code to share with other files and import and use code...
Read more >
How to import JavaScript files (import JS File into other JS File)
Import a JavaScript into another with import / export. Professional JavaScript Course: ...
Read more >
How to include a JavaScript file in another JavaScript file
In this module, we define exported functions in one file and import them in another example. There are two popular ways to call...
Read more >
Using JavaScript with Eclipse - Tutorial - Vogella.com
JavaScripts in the header is be executed when other JavaScript functions in the HTML body call them. 2. Getting Eclipse IDE for JavaScript...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found