How can I learn about the behavior of Glitch app containers and configuring them?

For example, some random tidbits I’ve learned through experience, but have never seen in documentation (is there documentation?)

  • The default exposed port is 3000
  • Modifying package.json will reload the app, installing npm modules that differ from the current cache of pnpm
  • Modifying a node.js entrypoint will reload the app?

How can I learn about the environment defaults and all of the ways to configure the app container behavior? Where is the documentation about how the app container works?

A lot of the information can be found here: https://glitch.com/help/all/
Personally, I learnt most of it just browsing and digging through the forums here

@jenn Can you provide some insight? Are there plans to produce documentation for Glitch container configuration?

It sounds like you’re a power user; you might like ~glitchnomicon. There’s less magic than you might think.

To try to answer your particular questions:

  1. You should listen on the PORT environment variable (process.env.PORT). The ~hello-express project illustrates how to do that. Yes, it’s probably equal to 3000 right now. No, you probably shouldn’t bake “3000” into your source code.

  2. If you have a package.json in the root of your project, then Glitch believes your project is a Node app, and uses the .scripts.start value from package.json to start your project. Also, if Glitch believes your project is a Node app, modifying package.json causes a reinstall lifecycle event, and modifying a .js file causes a restart lifecycle event.

  3. No, Glitch doesn’t have any particular treatment of node.js entrypoints - it’s changing .js files that causes a restart. If you’re running a Node app on Glitch, and you want more control over what files changing cause restarts, you can add a watch.json file - ~glitchnomicon has more.

Hope this helps,

Johnicholas

3 Likes

@Johnicholas Thanks for responding! ~glitchnomicon looks like a great resource. I have some additional questions at present:

  1. How can I create/modify environment variables which will be available to all processes involved in running the app (not just the interactive shell user)? I tried creating some in /app/.bashrc and sourcing that file from /app/.bash_profile, but it didn’t seem to work.

  2. How can I reboot the container itself? (Not just refreshing the app)

  3. How can I display dotfiles in the files viewer? There are some dotfiles that I want to be able to easily access and edit in the editor.

  4. watch.json: Where can I see the default json config file?

  5. Is there a way to interact with Glitch projects using VS Code without using the not-currently-open-source extension? See vscode-glitch/vscode-glitch#23

I have some documentation at https://github.com/youngchief-btw/Glitch-Docs
It doesn’t have everything, but is expanding and pull request & issues are welcome!

ANSWERS TO YOUR QUESTIONS ABOVE

  1. VARIABLE=VALUE if you mean system env variables, and if doing from inside node you can either take a look at https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback or use https://github.com/RIAEvangelist/node-cmd
  2. If you meant hard restart that has is done from Glitch admins atm
  3. I don’t know how you would access dotfiles in the editor but if you don’t mind a good alternative that runs in terminal use vim FILE. But sadly we can’t do so otherwise | Seeing the hidden files you can do with ls -a
  4. There isn’t a default file. If you specify it you are specifying certain behavior
  5. You can access Glitch projects with their Git URL (in my documentation) (NOTE: It won’t have real-time collaborative features) If you want to disable default commits --> https://stop-default-commits.glitch.me/README.md and run the command at the bottom.