DEV Community

liu550
liu550

Posted on

Problems with Node.js

Hi,

I am wondering why my server side code only outputs "Hi ${port}" on console without (1) showing the actual port number or (2) opening up the "locolhost:5000" web page. My command is "npm start server." The screenshots of (1) the code and the (2) scripts part of the package.json file are attached. Thanks!

https://dev-to-uploads.s3.amazonaws.com/i/fqccj2yqjogkszwzkjp5.png

https://dev-to-uploads.s3.amazonaws.com/i/w90w553emwra9deb7y8k.png

Top comments (7)

Collapse
 
kaleman15 profile image
Kevin Alemán • Edited

As others mentioned, use backtics in order to allow string interpolation.
And, regarding your server, it's indeed listening, but, it'll only respond to requests when you hit localhost:5000/api/sessions since you don't have a default handler for / route.

Collapse
 
liu550 profile image
liu550

Thanks!

Collapse
 
sergchr profile image
Serhii

Because your "Hi ${port}" is a regular string which doesn't allow to paste variables there. You meant to use a template string.

Collapse
 
liu550 profile image
liu550

Thanks! Besides, do you know from this code why locolhost:5000 did not load though?

Collapse
 
sergchr profile image
Serhii

The server handles only "/api/sessions" route, not the "/" you are trying to access by opening localhost:5000. You should add the handler for that too.

Collapse
 
rizkyrajitha profile image
Rajitha Gunathilake • Edited

use ` back ticks instead of ' single quotes in console.log .

Collapse
 
liu550 profile image
liu550

Thanks! Besides, do you know from this code why locolhost:5000 did not load though?