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}/`);
});
Also in JavaScript:
- create csv file nodejs
- jqgrid aftershowform
- javascript null check
- how to get a value into a react component
- javascript merge multidimensional array
- json placeholder api
- how to pass props in gatsby link using styledcomponent
- generate query string from urlsearchparams
- http request javascript
- truthy and falsy values in javascript
- javascript loop through object properties
- jsdoc doesn't see all folders
- adonis andwhere
- load_jsonl
- get current time in js
- How to show confirm message before delete using jquery
- Iterate with JavaScript For Loops
- space youtube
- refresh page on div click
- access to nested properties on javascript using property names
- get each primary colour and add into an array javascript
- how to get keys in an object javascript
- javascript vs java
- $(this).text() in jquery return white space