1

I'm new to node.js - I tried to create server with node and test if it's running, but the terminal doesn't print me out: Server is listening on port 3000.enter image description here

This is the code that I have written:

const express=require('express')
const app=express()

const port=process.env.port || 3000

app.listen(port)
console.log(`Server is listening on port ${port}`);
1
  • Does he print anything at all? A error message or something else? Commented Jan 17, 2022 at 9:12

2 Answers 2

2

You need to install express if you want to use the code. Use this command in the directory with the package.json

npm install express

The startpoint for the app is defined in the package.json as "main" : "yourScript.js"

After that you can start the code with the command

node yourScript.js

The server should start and print out your port.

Sign up to request clarification or add additional context in comments.

Comments

1

Your call to app.listen() needs two parameters You've provided the first which is the "port" The second one is a callback function where you can put your console.log() statement

app.listen(port, () => {
     console.log(`Server is listening on port ${port}`)
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.