NODE.JS How to find the PORT and HOSTNAME in a repository? #176020
Replies: 5 comments 2 replies
-
|
Hey there! Welcome to the GitHub community. Let me help you get that Node.js app running. The PORT and HOSTNAME aren't actually stored in the repository itself - they're runtime configuration values. Here's how to work with them: Finding Configuration:
Typical Setup Process: # Clone the repo
git clone <repo-url>
cd <repo-folder>
# Install dependencies
npm install
# Create .env file if needed
echo "PORT=3000" > .env
echo "HOSTNAME=localhost" >> .env
# Run it
node index.js
# or
npm startDefault Values:
You can also set these when running: PORT=3000 HOSTNAME=localhost node index.jsIf you share the specific repo you're trying to run, I can give you more targeted advice. Good luck! |
Beta Was this translation helpful? Give feedback.
-
|
Hey! I think I see what's happening here. You're trying to run a Node.js server on GitHub Pages, but unfortunately that's not gonna work. GitHub Pages only hosts static files (like HTML, CSS, JS that runs in the browser). It can't actually execute server code like your index.js file. You basically have two options, either convert the page to static HTML (to use GitHub Pages) or deploy the Node.js app somewhere else. To convert to static HTML: and keep your Then your URLs will work like: If you really want to use that index.js server code, you need to host it on a platform that runs Node.js, like Render/Railway/Vercel/Heroku etc. These platforms can actually execute your server code and handle the routing you wrote. |
Beta Was this translation helpful? Give feedback.
-
Fix: Importing Environment Variables in Node.jsIt looks like your code is trying to read variables from a ✅ Steps to Fix:1. Install dotenvnpm install dotenv ###2. Now cofig it // Example usage import 'dotenv/config'; // Example usage
Now process.env.PORT will be available in your app. ✅ |
Beta Was this translation helpful? Give feedback.
-
Fix: Import Environment Variables in Node.jsYour code needs a way to load variables from a .env file. The easiest fix is to use dotenv. Steps:
npm install dotenv
import 'dotenv/config';
const port = process.env.PORT || 3000;
PORT=3000 Add .env to your .gitignore to keep it out of version control. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How to launch a repository from a file index.js? How to find the PORT and HOSTNAME in a repository?
Beta Was this translation helpful? Give feedback.
All reactions