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 :: javascript set class of element 
Javascript :: readfile nodejs 
Javascript :: chart.js label word wrap 
Javascript :: Loop over all keys in the local storage 
Javascript :: extract payload of expired jwt token in js 
Javascript :: js  
Javascript :: how to get attr in vuejs 
Javascript :: moment time format by country 
Javascript :: fetch await reactjs 
Javascript :: javascript immediately invoked function expression 
Javascript :: Angular Laravel has been blocked by CORS policy: Request header field x-requested-with is not allowed by Access-Control-Allow-Headers in preflight response. 
Javascript :: javascript two character integer 
Javascript :: node how to stop NodeJS server process 
Javascript :: download jquery 
Javascript :: how to send query parameters in url vuejs 
Javascript :: react forms 
Javascript :: react proxy 
Javascript :: react usestate functional update 
Javascript :: let in javascript 
Javascript :: how to find last element of array react 
Javascript :: expo custom fonts 
Javascript :: jquery confirmation dialog example 
Javascript :: jquery map 
Javascript :: react native gradient 
Javascript :: post xml with axios nodejs 
Javascript :: change data js 
Javascript :: prisma seed 
Javascript :: usenavigate in react 
Javascript :: javascript is radio button checked 
Javascript :: ifsc code validation formik 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =