Http Server in nodejs is the bae of nodejs
Example code is the bellow, put an index.html in the same directory of the app of nodejs file.
You will see as a landing page index.html file will be called.
const http = require('http'); var fs = require('fs'); var data = fs.readFileSync('index.html'); http.createServer((req, res) => { res.status = 200; res.setHeader = (200,'content-type', 'text/html'); res.write(data.toString()); res.end(); }).listen(3000, () => { console.log('server running on port 3000'); });
0 Comments