Create a basic web server using Express js & HTML

Easiest way to create a basic webserver using express js.

We can use node js to create a web server using node js will a long time to create a server so we use express js for these types of thing.

First of all we are gonna create a new file named ser…


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

Easiest way to create a basic webserver using express js.

We can use node js to create a web server using node js will a long time to create a server so we use express js for these types of thing.

First of all we are gonna create a new file named server.js or you can use any name you want.

Coding Time

const express = require('express') // npm install express
const app = express()
const port = 3000

// Send text
app.get('/', (req, res) => {
  res.send('Hello World!')
})

// Send HTML File
app.get('/', (req, res) => {
  res.sendFile('./index.html')
})

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

Now run your code but how? lemme tell you open terminal in visual studio code or or open command promt in your folder then write down these commands in terminal.

First command

npm install express

Second command

npm install --save-dev nodemon
# To run our code we use this package.

Last command

nodemon server.js
# make sure to replace server.js with your file name

And thats for this post see you in another one


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


Print Share Comment Cite Upload Translate Updates
APA

pritudev | Sciencx (2021-09-25T14:04:14+00:00) Create a basic web server using Express js & HTML. Retrieved from https://www.scien.cx/2021/09/25/create-a-basic-web-server-using-express-js-html/

MLA
" » Create a basic web server using Express js & HTML." pritudev | Sciencx - Saturday September 25, 2021, https://www.scien.cx/2021/09/25/create-a-basic-web-server-using-express-js-html/
HARVARD
pritudev | Sciencx Saturday September 25, 2021 » Create a basic web server using Express js & HTML., viewed ,<https://www.scien.cx/2021/09/25/create-a-basic-web-server-using-express-js-html/>
VANCOUVER
pritudev | Sciencx - » Create a basic web server using Express js & HTML. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/25/create-a-basic-web-server-using-express-js-html/
CHICAGO
" » Create a basic web server using Express js & HTML." pritudev | Sciencx - Accessed . https://www.scien.cx/2021/09/25/create-a-basic-web-server-using-express-js-html/
IEEE
" » Create a basic web server using Express js & HTML." pritudev | Sciencx [Online]. Available: https://www.scien.cx/2021/09/25/create-a-basic-web-server-using-express-js-html/. [Accessed: ]
rf:citation
» Create a basic web server using Express js & HTML | pritudev | Sciencx | https://www.scien.cx/2021/09/25/create-a-basic-web-server-using-express-js-html/ |

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.