[Solved] I am getting a ReferenceError: html is not defined

You should take into account that nodejs often uses asyncronous calls, and this is the case with your code too. fs.readFile(‘index.html’, (err,html)=>{ if(err){ throw err; } console.log(html); // html works here }); console.log(html); // html is undefined here This should work fs.readFile(‘index.html’, (err,html)=>{ if(err){ throw err; } var server = http.createServer((req,res)=>{ res.statusCode = 200; res.setHeader(‘Content-type’,’text/plain’); … Read more

[Solved] find cities and country name from string

It all starts from function start() at the bottom. For displaying purpose i’ve used a small dataset but you can require the data from the json file by using const data = require(‘data.json’). I’ve tested for large dataset also, works like a charm. Hope it helps. const data = { “United States”:[ “Washington”,”Bratislava”,”Hard”,”Going”], “Afghanistan”: [ … Read more

[Solved] NPM command arguments

The -g is short for global. It installs the module globally instead of in the current directory. See this for more info: https://docs.npmjs.com/cli/npm solved NPM command arguments