Creating new server in node.js

Firstly install express

const express = require(“express”)
const app = express()

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

app.listen(4000, ()=>{
console.log(“server is running on port: 4000”)
})

Or if you want to this…


This content originally appeared on DEV Community and was authored by Muhammadaziz

Firstly install express

const express = require("express")
const app = express()

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

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

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)
})


This content originally appeared on DEV Community and was authored by Muhammadaziz


Print Share Comment Cite Upload Translate Updates
APA

Muhammadaziz | Sciencx (2021-12-26T16:44:11+00:00) Creating new server in node.js. Retrieved from https://www.scien.cx/2021/12/26/creating-new-server-in-node-js/

MLA
" » Creating new server in node.js." Muhammadaziz | Sciencx - Sunday December 26, 2021, https://www.scien.cx/2021/12/26/creating-new-server-in-node-js/
HARVARD
Muhammadaziz | Sciencx Sunday December 26, 2021 » Creating new server in node.js., viewed ,<https://www.scien.cx/2021/12/26/creating-new-server-in-node-js/>
VANCOUVER
Muhammadaziz | Sciencx - » Creating new server in node.js. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/26/creating-new-server-in-node-js/
CHICAGO
" » Creating new server in node.js." Muhammadaziz | Sciencx - Accessed . https://www.scien.cx/2021/12/26/creating-new-server-in-node-js/
IEEE
" » Creating new server in node.js." Muhammadaziz | Sciencx [Online]. Available: https://www.scien.cx/2021/12/26/creating-new-server-in-node-js/. [Accessed: ]
rf:citation
» Creating new server in node.js | Muhammadaziz | Sciencx | https://www.scien.cx/2021/12/26/creating-new-server-in-node-js/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.