Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

server html page using nodejs

const http = require('http')
const fs = require('fs')

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'content-type': 'text/html' })
  fs.createReadStream('index.html').pipe(res)
})

server.listen(process.env.PORT || 3000)
Comment

how to serve html node server

// app.js

const http = require('http');
const fs = require('fs')

// Create an instance of the http server to handle HTTP requests
let app = http.createServer((req, res) => {
    // Set a response type of plain text for the response
    res.writeHead(200, {'Content-Type': 'text/html'});
    fs.createReadStream('index.html').pipe(res)
});

// Start the server on port 3000
app.listen(3000, '127.0.0.1');
console.log('Node server running on port 3000');
Comment

PREVIOUS NEXT
Code Example
Javascript :: change select value jquery 
Javascript :: es6 method definition syntax 
Javascript :: adb reverse USB debugging 
Javascript :: axios delete request payload 
Javascript :: javascript currency format 
Javascript :: javascript file exists check 
Javascript :: jquery detect textarea change 
Javascript :: run function then empty it 
Javascript :: vue.js 
Javascript :: mongoose multiple populate 
Javascript :: double click in js 
Javascript :: jquery select first matching element 
Javascript :: moment get day 
Javascript :: sort an array of objects in javascript 
Javascript :: jQuery onclick not firing on dynamically inserted HTML elements 
Javascript :: npm run js file from command line 
Javascript :: circular progress for react 
Javascript :: Use Multiple Conditional Ternary Operators Javascript 
Javascript :: how to use the replace method in javascript 
Javascript :: get average and sum javascript 
Javascript :: javascript sum table row values 
Javascript :: call button click event in javascript 
Javascript :: No provider for ReducerManager 
Javascript :: first letter uppercase js 
Javascript :: Using Regular Expressions (regex) to Print JavaScript Number Format with Commas 
Javascript :: node js while loop with settimeout 
Javascript :: jquery hide select option 
Javascript :: js fetch api 
Javascript :: remove duplicate value from array 
Javascript :: xmlhttprequest js 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =