Reputation: 49
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}`);
Upvotes: 1
Views: 76
Reputation: 45
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}`)
}
Upvotes: 1
Reputation: 594
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.
Upvotes: 2