I want to make a very simple web server like this for example.
const http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.write("Hello!");
res.end();
}).listen(8080);
I put this code in WebStorm and ran it. Then I put in the same directory index.html file.
<body>
<button id="btn">Click Me</button>
<script src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script src="requester.js"></script>
</body>
I also put requester.js file in the same folder.
$('#btn').on("click", function () {
$.get('/', function () {
console.log('Successful.');
});
});
Then I execute command live-server in this folder where all files are. I don't know how to make the server to work on localhost. Thank you in advance.