Running POSTMAN Post/Get Requests in a Node.js server - issues with app crashing

import http from 'http';
const PORT = process.env.PORT;

const server = http.createServer((req, res) => {
console.log(req.url);
console.log(req.method);

res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('<h1>Hello World!</h1>');
});

server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
import http from 'http';
const PORT = process.env.PORT;

const server = http.createServer((req, res) => {
console.log(req.url);
console.log(req.method);

res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('<h1>Hello World!</h1>');
});

server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
No description
No description
18 Replies
CDL
CDLOP3mo ago
I should add the "start": script in package.json is
"start": "nodemon --env-file=.env server.js",
"start": "nodemon --env-file=.env server.js",
ἔρως
ἔρως3mo ago
what's in .env?
CDL
CDLOP3mo ago
just PORT=5000 or whatever PORT I was trying
ἔρως
ἔρως3mo ago
show me the file
CDL
CDLOP3mo ago
No description
ἔρως
ἔρως3mo ago
remove the ; that's a comment
CDL
CDLOP3mo ago
S.M.F.H.
ἔρως
ἔρως3mo ago
and whatever reader is reading the .env file is not good enough to understand comments
CDL
CDLOP3mo ago
Why in JS is it always a ; causing drama -.-
ἔρως
ἔρως3mo ago
that's not js that's a ini file, but with a different name but whatever is loading the .env file is not """"""""""""""""standard"""""""""""""""" compliant and just does whatever the fuck it wants in this case, it doesn't support comments with the value it's not a js problem, it's the .env reader problem
CDL
CDLOP3mo ago
ah ok good to know it was an easy fix 😄 thanks
ἔρως
ἔρως3mo ago
i mean, it says there that the port '5000;' is in use the ; there didn't spark anything?
CDL
CDLOP3mo ago
tbh, no, lol, because of js
ἔρως
ἔρως3mo ago
🤣 i get you it's still funny im not laughing at you, just at the situation 🤣 i've been there so many times
CDL
CDLOP3mo ago
This is 90% of the issues I have when writing code that involves JS, these bloody ;
ἔρως
ἔρως3mo ago
you can be absolutely maniacly maniac and not use them
CDL
CDLOP3mo ago
Can't say I've ever seen this before
No description
ἔρως
ἔρως3mo ago
that is unrelated, but it isnt unexpected, depending on the code

Did you find this page helpful?