How to host Your Node.js Project for free - Glitch.com Node tutorial

Last update: 08-07-2024

Glitch is a fantastic platform for hosting and collaborating on web projects. If you've got a Node.js application you'd like to share with the world, follow this guide to get it up and running on Glitch in no time.

Preparing Your Project

  1. Ensure your project has a package.json file. If it doesn't, create one by running:

    npm init -y
  2. In package.json, add a start script under the "scripts" section:

    "scripts": {
    "start": "node server.js"
    }

    Replace server.js with your application's main file. This step is crucial for Glitch to run your project automatically.

  3. Test your Node.js project locally to make sure it's working as expected.

  4. Create a zip file of your project, excluding the node_modules folder. The process differs depending on your operating system:

    Windows:

    • Open your project folder in File Explorer
    • Select all files and folders except node_modules
    • Right-click on the selection
    • Choose "Compress to ZIP file"

    macOS or Ubuntu:

    • Open Terminal
    • Navigate to your project directory
    • Run the following command:
    zip -r project.zip . -x "node_modules/*"

    This command creates a zip file named project.zip containing all files and directories in the current folder (.), excluding the node_modules directory.

Deploying to Glitch

  1. Log into Glitch.

  2. Click "New project" in the top right corner, then select "glitch-hello-node".

  3. Drag and drop your project's zip file onto the Glitch interface.

  4. In the right-hand menu, select "Assets". You should see your uploaded zip file.

  5. Open Glitch's built-in terminal by clicking the 'terminal' option at the bottom.

  6. Clear out the existing files:

    rm *
    rm -r *
  7. In the Assets panel, click on your zip file and select "Copy URL".

  8. Download your zip file to the Glitch environment:

    wget [paste your copied URL here]
  9. Verify the zip file is present:

    ls
  10. If a suffix was added to the file name and its extension is different than .zip, rename it to have a .zip extension:

    mv [original-filename] [new-filename].zip
  11. Unzip your project:

    unzip [your-file].zip
  12. Refresh the file tree:

    refresh

Viewing Your Live Site

To see your application in action, click the 'Share' button and use the "Live site" link provided.

Congratulations! Your Node.js project is now live on Glitch, ready for the world to see and for you to continue developing. Happy coding!

Using a custom domain

If you would like to use a custom domain for your Glitch.com website, follow this article.

StocksComparison.com ad

0 Comments

Add a new comment: