Learning Node.js 002 – Exporting Projects from Glitch.com

For the last couple weeks I’ve been playing around with Glitch.com. I don’t have much experience with Node.js, so it’s been a good way to learn more about Node.js without having to setup anything locally.

Glitch is great because you can learn a lot by checking out other projects and remixing their code. That being said, there is a pretty steep learning curve with Node.js.  Just to get started, you need to have a pretty good understanding of JavaScript and then you need to learn about npm, view engines, package.json files and so much more.  Glitch.com makes this easier, but there’s still a lot to learn. 

Glitch’s web based code editor is pretty good, but it’s still not the same as using a local editor, so I decided to export my project and develop it locally. It’s easy enough to export a project, but the exported project didn’t work right away.

Starting the project, I got the error:

Error: OAuth2Strategy requires a clientID option

I’m using the passport-oauth package and I discovered that the secrets I saved in the .env file on Glitch weren’t being loaded in my local environment.  Instead of using the .env file in the project, Node.js uses the variables in the .bash-profile file.  You can view those environment variables by adding this line to your project:

console.log(process.env);

To fix the issue with the project exported from Glitch, one option is to move your secrets to the .bash-profile file, but that can get messy, so another option is to use the dotenv npm package.

Add it to your app with:

npm install dotenv --save

And then ensure that it’s referenced in your project with:

require('dotenv').config();

Author: Kevin

WordPress and Laravel developer. Founder of ActiveTrackers.com.

Leave a Reply

Your email address will not be published. Required fields are marked *