Running NPM mapbox-map-image-export

2019-08-19 22:00发布

问题:

Im new to NPM/Node and am trying to run a seeingly simple command but am having trouble.

Im using VS Code and have used the terminal to clone the GIT repo. Then 'npm install'.

I am trying to run the command in the documentation 'export MAPBOX_TOKEN=YOUR_MAPBOX_API_PUBLIC_TOKEN'

Based on the instructions on the NPM page https://www.npmjs.com/package/mapbox-map-image-export

To do this I type in 'node' then the command above. However I just get three dots appear?

回答1:

In Unix systems, export is a Shell built-in command used to mark a variable for automatic export to the environment of subsequently executed commands. The Windows (MS-DOS) equivalent command is set.

So, to set the Mapbox token in Windows, just open a command prompt and execute:

set MAPBOX_TOKEN=YOUR_MAPBOX_API_PUBLIC_TOKEN

You can then run mapbox-map-image-export in the same command prompt session, like this:

export-map mapbox://styles/mapbox/streets-v9 -w=11in -h=8.5in -b=-7.1354,57.9095,-6.1357,58.516 -t=%MAPBOX_TOKEN% -o=lewis.png

Note that in Windows, %NAME% is used to get a variable value, so it's %MAPBOX_TOKEN% (and not $MAPBOX_TOKEN).

You can also specify the Mapbox token directly in the export-map command, without setting an environment variable, e.g.:

export-map mapbox://styles/mapbox/streets-v9 -w=11in -h=8.5in -b=-7.1354,57.9095,-6.1357,58.516 -t=YOUR_MAPBOX_API_PUBLIC_TOKEN -o=lewis.png


回答2:

The command (export MAPBOX_TOKEN=YOUR_MAPBOX_API_PUBLIC_TOKEN) you saw in the documentation aims at being run in a shell, not the node REPL.

Its job is to configure the token which can then be used by this package CLI. Technically it means:

Define an environment variable accessible to all the upcoming processes named MAPBOX_TOKEN with the value YOUR_MAPBOX_API_PUBLIC_TOKEN.

Executing it in a shell will enable the export-map command to grab it through process.env.