rpappalax / demo-hapi-twilio

Example Twilio voice app
0 stars 1 forks source link

Add ngrok as npm dep #4

Open pdehaan opened 9 years ago

pdehaan commented 9 years ago

OK, this is mildly neat, but your mileage may vary...

$ npm i ngrok -S

Now when you do npm install, it downloads ngrok into ./node_modules/. Now you can start the ngrok server via npm scripts (or calling manually via ./node_modules/.bin/ngrok or ./node_modules/ngrok/bin/ngrok).

But because ./node_modules/.bin/ is added to your $PATH via npm, you can just call ngrok as if it was installed globally:

  "scripts": {
    "start": "node app",
    "prestart": "ngrok 3000 &",
    "test": "echo \"Error: no test specified\" && exit 1"
  }
rpappalax commented 9 years ago

definitely would be useful for laptop testing. all the setup steps are maddening. i was thinking it might be useful to have something like an: npm start local (which fire up grok) vs. npm start which would assume you were already on an aws instance. for aws in our brave new qa jenkins world, we could have vagrant deploy the e2e test, setup the env, then call grunt to install the particulars.

pdehaan commented 9 years ago

Ah, good call. I forgot that ngrok is a ~13MB download, so we'd definitely want to try to optimize for AWS deployments by making it a devDependency so it doesn't get installed on a prod environment.

pdehaan commented 9 years ago

Also, in fxa-auth-server, I think we're using the envc module to help import a bunch of environment variables from an external file (saves you having to export a bunch of env vars manually):

# .env.dev
TWILIO_ACCOUNT_SID="YOUR TOKEN HERE"
TWILIO_AUTH_TOKEN="YOUR TOKEN HERE"

PORT=3000
// index.js
var env = require('envc')({
  booleans: true,
  numbers: true,
  nodeenv: 'dev'
})

console.log(JSON.stringify(env, null, 2))

/*
{
  "TWILIO_ACCOUNT_SID": "YOUR TOKEN HERE",
  "TWILIO_AUTH_TOKEN": "YOUR TOKEN HERE",
  "PORT": 3000
}
*/

console.log('SID:\t%s\nTOKEN:\t%s\nPORT:\t%d',
  process.env.TWILIO_ACCOUNT_SID,
  process.env.TWILIO_AUTH_TOKEN,
  process.env.PORT)

/*
SID:    YOUR TOKEN HERE
TOKEN:  YOUR TOKEN HERE
PORT:   3000
*/

Then obviously just add that .env.dev file to the .gitignore to avoid leaking creds.

rpappalax commented 9 years ago

oh man, where has this been all my life. thanks, that's very helpful. i've done the stupid thing of checking some creds already this year and had to nuke a project a few times. but i've now seen the light, Peter.