0

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?

RedCrusador
  • 675
  • 7
  • 19

2 Answers2

2

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
dilico
  • 694
  • 1
  • 6
  • 14
  • 1
    My OS is win 10. I am trying exact same commands but it is not working for me - no errors, no file generated. I know my token is valid because I am using it in a different project. – shobhit vaish Aug 29 '18 at 11:34
  • @shobhitvaish: let's figure this out! Can you please provide more info, e.g. node version, how you installed the package, command line you are running, etc.? I assume you are running it in Command Prompt, right? – dilico Aug 29 '18 at 14:37
  • @DiegoColantoni Thanks for your response! Details: Node version: **8.9.4**, command **npm install mapbox-map-image-export -g**, Command prompt: Tried both windows command prompt and nodejs command prompt – shobhit vaish Aug 30 '18 at 07:46
  • @shobhitvaish: it's strange that you don't get any error message... Have you tried running it directly from its location? Mine is located at `C:\Users\diego\AppData\Roaming\npm\node_modules\mapbox-map-image-export`. cd into it, and try to run: `node cmd.js 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`. Do you get any errors? – dilico Aug 30 '18 at 09:26
  • @DiegoColantoni No errors and again no file generated. I am looking for the file at this path: C:\Users\shobhitvaish\AppData\Roaming\npm\node_modules\mapbox-map-image-export – shobhit vaish Aug 30 '18 at 09:39
  • @shobhitvaish: it's really strange that is not returning any errors... Can you please edit the cmd.js file, and add a `console.log('logging')` statement under the comment at the top? Then run `node cmd.js -b=-7.1354,57.9095,-6.1357,58.516`. You should see a `logging` message, followed by an error complaining that you haven't provided the API token. In this way, we'll be sure that we are actually running it. – dilico Aug 30 '18 at 10:13
  • @DiegoColantoni Yes without token I get this error AssertionError [ERR_ASSERTION]: Missing --token (must pass a valid Mapbox API token) – shobhit vaish Aug 30 '18 at 10:36
  • @shobhitvaish: good! At least now we know that the script is being invoked. Maybe Electron is dying? Unfortunately you might have to do some debugging. The easiest thing to do is putting some `console.log` statements in `main.js` and follow the execution of the script. For example, you can check that the Electron window is being created (btw, you can show the window by setting: `win = new BrowserWindow({show: true})`). As far as I understood, `cmd.js` calls `main.js` which starts Electron and opens `index.html`. At that point `renderer.js` is invoked. – dilico Aug 30 '18 at 15:58
  • @DiegoColantoni Thanks for your guidance so far! It never hits createWindow() function in main.js - looks like Electron is dying. I have tried reinstalling but no luck. :( – shobhit vaish Aug 31 '18 at 06:16
  • It looked like the issue was passing the height argument as `-h`. For some reason, the Electron child process failed to be spawned. Specifying the height with the `--height` flag solved the problem. – dilico Aug 31 '18 at 12:38
  • @DiegoColantoni Thanks for your help and time! – shobhit vaish Aug 31 '18 at 12:39
  • @DiegoColantoni I want to talk to you about a project. Please let me know the best way to reach out to you. My skype is shobhitvaish@yahoo.com – shobhit vaish Sep 25 '18 at 10:58
  • @shobhitvaish, hi, did you get my email? – dilico Sep 28 '18 at 08:19
0

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.

aymericbeaumet
  • 6,853
  • 2
  • 37
  • 50