DEV Community 👩‍💻👨‍💻

Muhammadaziz
Muhammadaziz

Posted on

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

Top comments (2)

Collapse
 
revenity profile image
Revenity • Edited on

Put codes in javascript mode like this

const PORT = process.env.PORT || 4000

app.listen(PORT, () => {
    console.log(PORT)
});
Enter fullscreen mode Exit fullscreen mode
Collapse
 
suhakim profile image
sadiul hakim

Absolutely begging server. Not bad!

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠