This is an older post but I hope my suggestions might be useful to someone anyway.
The most common way probably is to use WPS using PyWPS or Zoo Project, both projects offer binding to GRASS GIS.
Another option is to call GRASS GIS directly from your server side application. This can be done by manual setting of GRASS GIS environment (since GRASS modules require GRASS session to run). This is described on GRASS user wiki, in documentation and finally on SE (Can't run grass tools from python script (grass 6.4, python 2.7, win7)).
Finally there is a new way in the development version of GRASS GIS of invoking GRASS modules or any scripts designed to run within GRASS environment/session. Here is a Python example:
import subprocess
grassbin = 'grass71' # we expect grass71 to be on path
mapset = '/home/john/grassdata/nc_spm_08_grass7_tests/PERMANENT/'
subprocess.check_call([grassbin, mapset, '--exec', 'g.version', '-g'])"
I'm not sure how exactly this looks like in NodeJS but you may want to look at Execute a command line binary with Node.js. The interface was added just recently and it is not in stable release yet, it's quite usable however. In older versions you can get similar but limited functionality by setting the GRASS_BATCH_JOB
environment variable. You can learn more in the documentation or by running grass71 --help
. The general syntax is:
grass_executable full/path/to/mapset --exec module module=parameters -andflags
grass_executable full/path/to/mapset --exec custom_script.py
grass_executable -standard -flags full/path/to/mapset --exec ...
Note that in general, GRASS modules and scripts written specifically for GRASS require GRASS session to be active. Standard way is to run GRASS program which starts/sets the session. The session is typically interactive (command line and/or GUI). When using GRASS functionality from other programs, the session/environment must be set up in some way. PyWPS and Zoo Project will help you with that or you can do it completely on your own (second suggested option) or ideally you can use the actual GRASS executable which will run specified module or script in the proper session using the new --exec
flag or GRASS_BATCH_JOB
variable (this is the last suggested option).