Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

mage-server

> 编程语言
Open source

Mage Server

100 stars0 likes1 views
WebsiteGitHub

About

Mage Server

Mage Web Service & Web App

The Mage platform, provides mobile situational awareness and data collection capabilities. This project comprises the ReST API web service the Mage client apps use to submit and fetch Mage data, as well as the browser-based web app. The Mage web app provides user interfaces to view and edit Mage observations similar to the Mage mobile apps, and additionally provides the administrative UI to manage the Mage server settings, access control, events, data collection forms, etc.

Mage was developed at the National Geospatial-Intelligence Agency (NGA) in collaboration with BIT Systems. The government has "unlimited rights" and is releasing this software to increase the impact of government investments by providing developers with the opportunity to take things in new directions. The software use, modification, and distribution rights are stipulated within the Apache license.

Technology stack

Mage is built using the MEAN stack. The components of the MEAN stack are as follows:

  • MongoDB - a NoSQL JSON document database
  • Express.js - a web server framework for Node to handle ReST API requests
  • Angular - a JavaScript MVC framework for web app front-ends
  • Node.js - a software platform for scalable server-side and networking applications.

The Mage server code is TypeScript for strong typing, which transpiles to JavaScript that runs on Node.js. At the time of this writing, the transition of legacy JavaScript to TypeScript is still in progress.

Project structure

The Mage server project is essentially a monorepo with several NPM package components that assemble into a running server instance.

service

The service directory contains the @ngageoint/mage.service package. This is the backend ReST web service that the web and mobile apps consume.

web-app

The web-app directory contains the @ngageoint/mage.web-app package. The package is the bundled, Angular-based web app Mage client that includes standard user functionality as well as access administrative functions.

core-lib

The core-lib directory is a descendant of the web-app directory that contains the @ngageoint/mage.web-core-lib package. The package is an Angular library that includes shared elements that both the web app uses, and that web plugins can use to add custom UI elements to the web app.

instance

The instance directory is a development instance of the Mage server whose dependencies are the relative paths to the other packages in the project. This is useful as an example of how to assemble and configure a Mage server instance, as well as to run and test the server during development.

plugins

The plugins directory contains various plugin packages that the Mage team maintains as part of the Mage server open source project. Some of these are automatically bundled with Mage server releases, and some serve as examples and/or development utilities.

Running a Mage server

The Mage server Node.js app is generally intended to run on Unix-like platforms. The server should run on Windows, but be aware some path-separator related bugs may exist

Install Node.js

The Mage server is a Node.js application, so of course you'll need to install Node on your platform of choice. Node Version Manager is a nice tool to use for installing and managing different versions of Node, as opposed to various package managers. At the time of this writing, Mage requires Node > 18.x. Developers should use the latest LTS, 20.x at the time of this writing.

Install MongoDB

Before running a Mage server, you'll need to install and start MongoDB. At the time of this writing, Mage supports MongoDB version 6.x (6.0).

Install Mage server packages

Starting with release 6.2.2, the Mage server packages are available from the NPM registry.

bash
mkdir mage
cd mage
npm install --omit dev \
@ngageoint/mage.service \
@ngageoint/mage.web-app \
@ngageoint/mage.image.service \

That will yield a package.json file that looks something like

json
{
  "dependencies": {
    "@ngageoint/mage.image.service": "^1.0.4",
    "@ngageoint/mage.service": "^6.2.12",
    "@ngageoint/mage.web-app": "^6.2.12"
  }
}

as well as a package-lock.json file and node_modules directory containing all of the Mage server's dependencies.

Register plugins

As the example instance configuration demonstrates, you'll need to tell the Mage service what plugins to load. See the plugins entry in the configuration object, as well as the plugins readme. Note that the @ngageoint/mage.image.service package in the dependency list above is a plugin package, and resides in this monorepo.

Run mage.service script

The @ngageoint/mage.service package includes a [mage.service bin script for starting the server process. From the instance directory, you can run npx @ngageoint/mage.service --help to see the configuration options. Also, the instance directory in this project has an example configuration script which the mage.service script would load with the -C flag, e.g., mage.service -C config.js.

On Windows Server installations, running the command node node_modules\@ngageoint\mage.service\bin\mage.service.js in the instance directory will execute the mage.service script.

Configuration merging

Because the mage.service script uses the Commander library, you can set most of the configuration options with environment variables and/or command line switches. You can also pass options from a JSON file or JSON string literal via the -C (or --config, or MAGE_CONFIG environment variable) command line switch. The mage.service script merges options from command line switches, environment variables, and JSON object, in descending order of precedence. This enables you to have a base configuration file, then override the file's entries with environment variables and/or command line switches as desired. The full configuration object for the -C/MAGE_CONFIG environment variable must have the following form.

json
{
  "mage": {
    "address": "0.0.0.0",
    "port": 1234,
    // etc.
  }
}

The -C option can be a path to a .json file that contains the configuration object, or a Node JavaScript module whose export is a configuration object,

javascript
module.exports = {
  mage: {
    // config options ...
  }
}

or a literal JSON value.

bash
mage.service -C /mage/config.json
# or
mage.service -C /mage/config.js
# or
mage.service -C '{ "mage": { "mongo": { "connTimeout": 5000 }}}'

To see your full effective configuration, add the --show-config switch to the command, and the mage.service will print the configuration as a JSON string and exit without starting the server.

 npx @ngageoint/mage.service  --show-config

By default, the Mage server will attempt to create and use a directory at /var/lib/mage for storing data and media such as videos, photos, and icons. If the system user account that runs the Mage server does not have permission to create that directory, you must create it before starting the server. Of course, you can change the directories the server uses through the script command line switches and/or environment variables.

For convenience, the Mage server project contains an environment script that you can copy and customize. You can configure the Mage system user account to source the script at login.

The Node Mage server runs on port 4242 by default. You can access the Mage web app in your web browser at http://127.0.0.1:4242 if you are running Mage locally.

Running with Docker

Refer to the Docker README for details on running the Mage server using Docker.

Production notes

When running a publicly accessible production server, consider the following points.

Configuration location

If all of your Mage server configuration options come from environment variables, as should be the case with most cloud server deployments, you will not need to worry about the location of a configuration file. If you are using a JSON or JavaScript module configuration file, be sure to the store the file in a location outside where you have installed the Mage server packages. For example, if you installed the Mage server in /opt/mage, keep your configuration in some non-overlapping directory like /etc/mage.json. That way, if you decide to delete the contents of /opt/mage and start fresh, your configuration will remain intact.

Running with forever

Use a tool like forever to run the Mage server process as a daemon in a production environment. forever will restart the Mage server process if it happens to terminate unexpectedly. First, you'll need to install forever.

bash
npm install -g forever

To run the Mage server with forever, you can start the server like the following, assuming you are in the directory where you have installed the Mage server packages.

bash
forever start ./node_modules/.bin/mage.service 

NOTE: The forever readme now indicates that the project no longer has a dedicated developer and is totally reliant on community updates. Try using the newer tools pm2 or nodemon for running mage.service persistently in production.

Running as a Windows Service

To continuously run mage.service on a Windows environment, it is recommended to create a Windows service using a tool such as node-windows.

First you'll need to install node-windows

bash
npm install -g node-windows

Then a script is needed to configure and create the Windows service.

javascript
var Service = require('node-windows').Service;

// Create a new service object
var svc = new Service({
  name:'Mage Service',
  description: 'To run Mage Server as a windows service',
  script: '{Mage Install Directory}\\node_modules\\@ngageoint\\mage.service\\bin\\mage.service.js',
  nodeOptions: [
  ]
  //, workingDirectory: '...'
  //, allowServiceLogon: true
});

// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
  svc.start();
});

svc.install();

Running the script creates a new Windows service with the given name. You can then configure the Windows server to automatically start the Mage service.

HTTPS/TLS

As with any production web application, you should use a reverse proxy such as Apache HTTP Server or NGINX to force external connections to use HTTPS and run the Mage server Node process on a private subnet host. The Mage server Node application itself does not support HTTPS/TLS connections.

IMPORTANT: Be sure your reverse proxy properly sets the X-Forwarded-Host and X-Forwarded-Proto headers properly. The Mage Node.js app builds URLs, via Express.js, that Mage clients use to request resources.

For Microsoft ISS installations, in addition to running a reverse proxy, you

Issues· 3 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言