Creating new server in node.js

muhammadaziz107

Muhammadaziz

Posted on December 26, 2021

Creating new server in node.js

Firstly install express

const express = require("express")
const app = express()
Enter fullscreen mode Exit fullscreen mode

Then add to server.js or other js files to listen port

app.listen(4000, ()=>{
console.log("server is running on port: 4000")
})
Enter fullscreen mode Exit fullscreen mode

Or if you want to this way. This way is also good. It's best practices

const PORT = process.env.PORT || 4000

app.listen(PORT, ()=>{
console.log(PORT)
})
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
muhammadaziz107
Muhammadaziz

Posted on December 26, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related