You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Server running on mode undefined port number undefined
My Code
importdotenvfrom'dotenv'importexpressfrom"express";importcolorsfrom"colors"dotenv.config();constapp=express();app.get('/',(req,res)=>{res.send("<h1> Welcome to my aapp</h1>");})//portconstport=process.env.PORTapp.listen(port,()=>{console.log(`Server running on mode ${process.env.DEV_MODE} port number ${port}`.bgYellow.black)})
The text was updated successfully, but these errors were encountered:
It seems that the issue might be due to the way you're setting the port. If the .env file is configured correctly, ensure that the .env file contains the PORT variable and it's being read by the dotenv package. Additionally, verify that the .env file is in the root directory of your project.
Make sure your .env file looks like this: PORT=3000
Then, ensure that you've installed the necessary dependencies (dotenv, express, etc.) and check if you're using the correct syntax to load environment variables with dotenv.
Here's a revised version of your code:
import dotenv from 'dotenv';
import express from 'express';
import colors from 'colors';
dotenv.config();
const app = express();
app.get('/', (req, res) => {
res.send('<h1>Welcome to my app</h1>');
});
// Get the port from the environment variable or default to 3000
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server running on mode ${process.env.DEV_MODE || 'development'} on port number ${port}`.bgYellow.black);
});
Notes
Error output
My Code
The text was updated successfully, but these errors were encountered: