title: firebase cloud function process.env.FIREBASE_CONFIG not working after 1.0.0 with SyntaxError: Unexpected token o in JSON at position 1 error
body: <p>days ago the cloud function is out of beta and the following guide was provided </p>
  
  <p><a href="https://firebase.google.com/docs/functions/beta-v1-diff#functionsconfigfirebase_removed" rel="nofollow noreferrer">Firebase SDK for Cloud Functions Migration Guide: Beta to version 1.0</a></p>
  
  <p>this example was provided to know which project is currently used</p>
  
  <pre><code>let firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG);
  /* {  databaseURL: 'https://databaseName.firebaseio.com',
         storageBucket: 'projectId.appspot.com',
         projectId: 'projectId' }
  */
  </code></pre>
  
  <p>And I tried to add it in my app</p>
  
  <pre><code>// import * as functions from 'firebase-functions';
  
  const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  
  export function environment(){
  const object:any ={}
  let firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG);
      switch(firebaseConfig.projectId){
          case 'app1-id':
              object.projectId = 'app1-id'
              object.keyFilename = 'dev.json'
              break;
          case 'app2-id':
              object.projectId = 'app2-id'
              object.keyFilename = 'staging.json'
              break;
          case 'app3-id':
              object.projectId = 'app3-id'
              object.keyFilename = 'prod.json'
              break;
          default:
              object.projectId = 'app1-id'
              object.keyFilename = 'dev.json'
        }
  return object
  };
  </code></pre>
  
  <p>but I got the following error</p>
  
  <pre><code>Error: Error occurred while parsing your function triggers.
  
  SyntaxError: Unexpected token o in JSON at position 1
      at JSON.parse (&lt;anonymous&gt;)
      at Object.environment (/home/hady/Documents/td_functions_outside/functions/lib/helper/env.js:8:31)
      at Object.&lt;anonymous&gt; (/home/hady/Documents/td_functions_outside/functions/lib/helper/pubSub.js:5:31)
      at Module._compile (module.js:652:30)
      at Object.Module._extensions..js (module.js:663:10)
      at Module.load (module.js:565:32)
      at tryModuleLoad (module.js:505:12)
      at Function.Module._load (module.js:497:3)
      at Module.require (module.js:596:17)
      at require (internal/module.js:11:18)
  npm ERR! code ELIFECYCLE
  npm ERR! errno 1
  npm ERR! functions@ deploy: `firebase deploy --only functions`
  npm ERR! Exit status 1
  npm ERR!
  npm ERR! Failed at the functions@ deploy script.
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /home/hady/.npm/_logs/2018-04-06T16_30_50_119Z-debug.log
  npm ERR! code ELIFECYCLE
  npm ERR! errno 1
  npm ERR! functions@ deploy:dev: `firebase use dev &amp;&amp; npm run deploy`
  npm ERR! Exit status 1
  npm ERR!
  npm ERR! Failed at the functions@ deploy:dev script.
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /home/hady/.npm/_logs/2018-04-06T16_30_50_135Z-debug.log
  </code></pre>
  
  <p>this is the debug file</p>
  
  <pre><code>0 info it worked if it ends with ok
  1 verbose cli [ '/usr/bin/node', '/usr/local/bin/npm', 'run', 'deploy:dev' ]
  2 info using npm@5.6.0
  3 info using node@v8.10.0
  4 verbose run-script [ 'predeploy:dev', 'deploy:dev', 'postdeploy:dev' ]
  5 info lifecycle functions@~predeploy:dev: functions@
  6 info lifecycle functions@~deploy:dev: functions@
  7 verbose lifecycle functions@~deploy:dev: unsafe-perm in lifecycle true
  8 verbose lifecycle functions@~deploy:dev: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/hady/Documents/td_functions_outside/functions/node_modules/.bin:/home/hady/.local/share/umake/bin:/home/hady/bin:/home/hady/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
  9 verbose lifecycle functions@~deploy:dev: CWD: /home/hady/Documents/td_functions_outside/functions
  10 silly lifecycle functions@~deploy:dev: Args: [ '-c', 'firebase use dev &amp;&amp; npm run deploy' ]
  11 silly lifecycle functions@~deploy:dev: Returned: code: 1  signal: null
  12 info lifecycle functions@~deploy:dev: Failed to exec deploy:dev script
  13 verbose stack Error: functions@ deploy:dev: `firebase use dev &amp;&amp; npm run deploy`
  13 verbose stack Exit status 1
  13 verbose stack     at EventEmitter.&lt;anonymous&gt; (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16)
  13 verbose stack     at emitTwo (events.js:126:13)
  13 verbose stack     at EventEmitter.emit (events.js:214:7)
  13 verbose stack     at ChildProcess.&lt;anonymous&gt; (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
  13 verbose stack     at emitTwo (events.js:126:13)
  13 verbose stack     at ChildProcess.emit (events.js:214:7)
  13 verbose stack     at maybeClose (internal/child_process.js:925:16)
  13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
  14 verbose pkgid functions@
  15 verbose cwd /home/hady/Documents/td_functions_outside/functions
  16 verbose Linux 4.8.0-32-generic
  17 verbose argv "/usr/bin/node" "/usr/local/bin/npm" "run" "deploy:dev"
  18 verbose node v8.10.0
  19 verbose npm  v5.6.0
  20 error code ELIFECYCLE
  21 error errno 1
  22 error functions@ deploy:dev: `firebase use dev &amp;&amp; npm run deploy`
  22 error Exit status 1
  23 error Failed at the functions@ deploy:dev script.
  23 error This is probably not a problem with npm. There is likely additional logging output above.
  24 verbose exit [ 1, true ]
  </code></pre>
  
  <p>and my packge.json got the following </p>
  
  <pre><code>"firebase-admin": "^5.11.0",
  "firebase-functions": "^1.0.0",
  </code></pre>
  
  <p>with firebase-tools updated</p>
  
  <pre><code>hady@hady-HP-Notebook:~/Documents/td_functions_outside/functions$ firebase -V
  3.18.1
  </code></pre>
  
  <p>nodejs version</p>
  
  <pre><code>hady@hady-HP-Notebook:~/Documents/td_functions_outside/functions$ node -v
  v8.10.0
  </code></pre>