burnedikt / diasend-nightscout-bridge

Synchronize your diasend data to nightscout.
MIT License
18 stars 18 forks source link

Running Standalone - yarn start not working #22

Closed jay-beco closed 1 year ago

jay-beco commented 1 year ago

Hey Benedikt - stuck at running the script as a standalone solution.

When trying to start "yarn start" it tells me:

janbeco@Mac5k diasend-nightscout-bridge % yarn start yarn run v1.22.19 error Command "start" not found. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. janbeco@Mac5k diasend-nightscout-bridge %

I also couldn't figure out what I have to rename the .env.example file to. Tried all different options. But when using the command "yarn run run" it tells me:

janbeco@Mac5k diasend-nightscout-bridge % yarn run run
yarn run v1.22.19 $ yarn build && node dist/run.js $ tsc

/Users/janbeco/Documents/GitHub/diasend-nightscout-bridge/dist/index.js:183 throw Error("Diasend Username not configured"); ^

Error: Diasend Username not configured at startPumpSettingsSynchronization (/Users/janbeco/Documents/GitHub/diasend-nightscout-bridge/dist/index.js:183:15) at Object. (/Users/janbeco/Documents/GitHub/diasend-nightscout-bridge/dist/run.js:5:41) at Module._compile (node:internal/modules/cjs/loader:1218:14) at Module._extensions..js (node:internal/modules/cjs/loader:1272:10) at Module.load (node:internal/modules/cjs/loader:1081:32) at Module._load (node:internal/modules/cjs/loader:922:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12) at node:internal/main/run_main_module:23:47

Node.js v19.3.0 error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

It looks like the env variables cant be found. Appreciate any pointers.

Thanks a lot and GREAT work! Looking forward getting this thing running.

All the best from almost Munich, .Jx

jay-beco commented 1 year ago

In the meantime I hardcoded the credentials in config.ts. Can start it now "yarn run run".... But i guess there is a "better" option to do that?! ;)

burnedikt commented 1 year ago

There are a variety of options of passing environment variables to the command you're running.

The easiest (but also most verbose way) would be to specify them right in front of the yarn run run command like:

DIASEND_USERNAME='john.doe@example.org' DIASEND_PASSWORD='my-pasword' yarn run run

Note that this will only work on UNIX-based shells so it will not work on Windows.

As for the .env.example file, the values in there need to be loaded manually or via a solution like direnv.

jay-beco commented 1 year ago

This info should maybe go in your readme. It starts with editing all the details in the .env.example file but it doesn't say what to do with it afterwards. As well as (at least on macos) the yarn start command is not working....

As for the .env.example file, the values in there need to be loaded manually or via a solution like direnv.

How would the manual way work? I wasn't able to figure out how to define the variables... (on macos)! Thanks.

jay-beco commented 1 year ago

In the meantime I hardcoded the credentials in config.ts. Can start it now "yarn run run".... But i guess there is a "better" option to do that?! ;)

PS: is just putting the login credentials in config.ts wrong or would/does that also work ;)

burnedikt commented 1 year ago

In the meantime I hardcoded the credentials in config.ts. Can start it now "yarn run run".... But i guess there is a "better" option to do that?! ;)

PS: is just putting the login credentials in config.ts wrong or would/does that also work ;)

it surely does work. One downside is that it might break whenever config.ts changes in future versions of the software so that your local modifications are overwritten and - at least as a developer - there's a high risk to accidentally commit the local changes to version control and thereby leak your credentials to the world.

burnedikt commented 1 year ago

This info should maybe go in your readme. It starts with editing all the details in the .env.example file but it doesn't say what to do with it afterwards. As well as (at least on macos) the yarn start command is not working....

As for the .env.example file, the values in there need to be loaded manually or via a solution like direnv.

How would the manual way work? I wasn't able to figure out how to define the variables... (on macos)! Thanks.

Manually, I'd suggest to prefix each line in the .env file with export, i.e.

export DIASEND_CLIENT_ID="a486o3nvdu88cg0sos4cw8cccc0o0cg.api.diasend.com"
export DIASEND_CLIENT_SECRET="8imoieg4pyos04s44okoooowkogsco4"
export DIASEND_USERNAME="<your-diasend-username>"
export DIASEND_PASSWORD="<your-diasend-password>"
export NIGHTSCOUT_URL="<my-nightscout-url>"
export NIGHTSCOUT_API_SECRET="<nightscout-api-secret>"

You can then just run source .env from within your terminal before running yarn run run and all the variables should be set.

Alternatively, if you don't want to add the export statement, you can try some bash-stuff like eval $(cat .env) yarn run run (untested).

I personally always use direnv as it will automatically load the .env file when I cd into the directory (given that there's a suitable .envrc file like in this repository).