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
-
Ensure your project has a
package.json
file. If it doesn't, create one by running:npm init -y
-
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. -
Test your Node.js project locally to make sure it's working as expected.
-
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 thenode_modules
directory.
Deploying to Glitch
-
Log into Glitch.
-
Click "New project" in the top right corner, then select "glitch-hello-node".
-
Drag and drop your project's zip file onto the Glitch interface.
-
In the right-hand menu, select "Assets". You should see your uploaded zip file.
-
Open Glitch's built-in terminal by clicking the 'terminal' option at the bottom.
-
Clear out the existing files:
rm * rm -r *
-
In the Assets panel, click on your zip file and select "Copy URL".
-
Download your zip file to the Glitch environment:
wget [paste your copied URL here]
-
Verify the zip file is present:
ls
-
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
-
Unzip your project:
unzip [your-file].zip
-
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.