Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nodejs: http:send HTML to the Browser

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

const server = http.createServer((req, res) => {
    console.log(req.url, req.method);

    // Set Header Content
    res.setHeader('Content-Type', 'text/html');

    fs.readFile('./views/index.html', (err, data) => {
        if (err) {
            console.log('Oops!!! Have error' + err);
            res.end();
        } else {
            // res.write(data);
            res.end(data);
        }

    });
});

server.listen(3000, 'localhost', () => {
    console.log('Listening for request on PORT 3000');
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: standalone apk build expo 
Javascript :: use js to get select value 
Javascript :: Invariant Violation: "main" has not been registered. This can happen if: * Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project. 
Javascript :: json comments 
Javascript :: refresh div after ajax success 
Javascript :: google gapi auth2 get current token 
Javascript :: js remove specific item from array 
Javascript :: react native flexbox 2 columns 1 fixed width 
Javascript :: how to create json file in c# 
Javascript :: new map js 
Javascript :: max js 
Javascript :: js while continue 
Javascript :: jquery date 
Javascript :: mongoose updateone example 
Javascript :: jsx loop array 
Javascript :: wait for promise javascript 
Javascript :: convert json to array 
Javascript :: dynamic copyright year javascript 
Javascript :: How to set up ejs 
Javascript :: run react app 
Javascript :: looping through local storage javascript 
Javascript :: Round date to future 5min 
Javascript :: js add to map 
Javascript :: icomoon react native 
Javascript :: nodejs end process 
Javascript :: forceupdate usereducer 
Javascript :: socket emit to specific room using nodejs socket.io 
Javascript :: selector jquery 
Javascript :: why can i put comments in some json files 
Javascript :: classic asp get json from file 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =