Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nodejs how to send html

var app = express();
app.get('/test', function(req, res) {
    res.sendFile('views/test.html', {root: __dirname })
});
Comment

nodejs: basic: send html page to Browser

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



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

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

    // Send HTML File to Browser
    fs.readFile('./views/index.html', {encoding: 'utf-8'}, (err, data) => {
        if (err) {
            console.log(err);
            res.end();
            return
        }
        res.write(data);
        res.end();
    })
});

server.listen(5000, 'localhost', () => {
    console.log('Server is listening on PORT: 5000...');
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: password reset passport-local mongoose 
Javascript :: route not getting refresh with different id in angular 
Javascript :: how to get the value of textarea in react 
Javascript :: vuejs take rgba values from coordinate 
Javascript :: overflowx 
Javascript :: accordion reatjs 
Javascript :: react render for loop 
Javascript :: leaflet dark mode 
Javascript :: array remove first element js 
Javascript :: Adding User And Hashed Password In ExpressJS 
Javascript :: check empty object javascript 
Javascript :: react-moralis 
Javascript :: how to add id in jquery 
Javascript :: angular infinite scroll 
Javascript :: delete duplicate array javascript 
Javascript :: replace characters form array 
Javascript :: how to console.log variable in js 
Javascript :: node js add new object to object array json 
Javascript :: copy object with new property in js 
Javascript :: Relative Time momentjs 
Javascript :: Different between for of loop and for in loop in js 
Javascript :: json stringify number 
Javascript :: how to give icon in input type file react 
Javascript :: jQuery intellisence in VSCode 
Javascript :: javascript update value when slider moves javascript 
Javascript :: return inside ternary operator javascript 
Javascript :: proper to mixed fraction in javascript 
Javascript :: math js 
Javascript :: sequelize one to many 
Javascript :: javascript count number of clicks limit 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =