Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

node js send javascript

const fs = require("fs");
const hostname = "127.0.0.1";
const port = 3000;

// use createReadStream instead to save memory
const index = fs.readFileSync("index.html");
const java = fs.readFileSync("javascript.js");

// this is our request handler
const server = http.createServer((req, res) => {
 if (req.url === "/") {
   res.setHeader("Content-Type", "text/html");
   res.write(index);
 }
 if (req.url === "/javascript.js") {
   res.setHeader("Content-Type", "text/javascript");
   res.write(java);
 }
 res.statusCode = 200;
 //   res.writeHead(200, java);
 res.end();
});

server.listen(port, hostname, () => {
 console.log(`Server running at http://${hostname}:${port}/`);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript fetch request GET 
Javascript :: javascript find in nested array 
Javascript :: tostring() javascript 
Javascript :: image view component react js 
Javascript :: jquery: get selected option of the drop down list 
Javascript :: react memo 
Javascript :: js get current year last 2 digits substring 
Javascript :: chai test throw error 
Javascript :: moment set time 
Javascript :: how to comments in json file 
Javascript :: api testing app with websocket 
Javascript :: new Date().now 
Javascript :: how to tell what page you are on shopify liquid 
Javascript :: THE REDUCE() METHOD IN JAVASCRIPT 
Javascript :: array includes 
Javascript :: javascript create folder 
Javascript :: vue localstore 
Javascript :: make angular to run on a different port 
Javascript :: javascript includes check object 
Javascript :: json stands for 
Javascript :: webpack babel loaders/plugin installation 
Javascript :: google analyics send event 
Javascript :: stopwatch with javascript 
Javascript :: jquery ui timepicker 
Javascript :: delete element javascript 
Javascript :: segregate value by _ using jquery like explode 
Javascript :: lodash compare array without order 
Javascript :: convert set to array javascript 
Javascript :: js initialize array with values 
Javascript :: json deep dot 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =