Sunday 12 November 2017

Trying to use .js in HTML...

Hey, I have the following code, where I want to use main.js(it uses node.js) in my .html.main.jsconst http = require('http'); const fs = require('fs'); const readline = require('readline'); var server = http.createServer( (req, res) => { res.writeHead(200, {'Content-Type': 'text/html'}); fs.createReadStream(__dirname + '/index.html').pipe(res); }).listen(3000, '127.0.0.1'); console.log('Server started...') function readStream() { var stream = fs.createReadStream('C:/Users/Mat/Desktop/readMe.txt', 'utf8'); var rl = readline.createInterface({ input: stream }).on('line', line => { console.log(line); }); } index.html For some reason, the function readStream() is always undefined. Why is that? Both files are located in the same folder.Thanks!

Submitted November 12, 2017 at 07:26PM by Fasyx

No comments:

Post a Comment