Change the internal behavior of starting projects

Is there a way I can change how projects are started? For example using Node.js, can I change the default behavior to use some other script instead of start?

There are options but could you explain what you are trying to accomplish? The start command is built into NPM but what it does is defined by you. It doesn’t have to start node if you don’t want it to and it can be set to run any .js file you define.

If you must use something other than the start script, then there are some not-officially-supported other project types. One is “custom,” which lets you specify what to run in a glitch.json file. I searched around on the forum, and here’s one result:

See the section there on glitch.json.

There might be some complications if the app really is on Node.js though. For one thing, Glitch’s “Node” or “fullstack” project type provides the logic for selecting the version of Node.js that the node command refers to. Without this logic, there’s no node command in the default PATH. So I think there’s some extra work to reach into the right place where the version of Node.js you need.

So anyway, there’s that. You’ll be rebuilding some of the machinery yourself in order to change this one little thing. Please do take one more opportunity to think about whether it’s worth it to go down this route.

The ~glitchnomicon offers more information on the usage of glitch.json.

Using glitch.json

You can explicitly tell Glitch how to run your code and install dependencies by putting a glitch.json file in the root of your project. It supports the following options:

  • start: command to run to start the project. start commands should result in something listening on the project’s $PORT.
  • install: command to run to install any needed dependencies to run the project.
  • watch: configure the Glitch watcher. Takes the same options as watch.json
1 Like