Monday, 5 June 2017

Cannot GET /nodesockets/index.html error coming

I am a beginner to Webstorm IDE and js in general So I made three files given below for making a chat application. When all these files were made, I typed the following command in the terminal

node index.js

Giving me the outcome on the terminal as

server listening on port 8090

After that I proceeded with opening the HTML file. There was a small icon of Google Chrome on the index.html file which I selected, opening a webpage. When I started to inspect the webpage, it showed me an error like this

Cannot GET /nodesockets/index.html

What should I do and I am not clearly understanding what is causing the error

package.json

{
  "name": "nodesockets",
  "version": "1.0.0",
  "description": "android node chat",
  "main": "index.js",
  "scripts": {
    "test": "make test"
  },
  "author": " ",
  "license": "ISC",
  "dependencies": {
    "express": "^4.15.3",
    "socket.io": "^2.0.2"
  }
}

index.js

 var app = require('express')();
    var http = require('http').Server(app);
    var io = require('socket.io')(http);

    io.on('connection', function (socket) {
        console.log("one user connected" + socket.id);
    })
    http.listen(8090, function () {
        console.log('server listening on port 8090');
    })

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Node Socket</title>
    <script src="http://localhost:8090/socket.io/socket.io.js"></script>
    <script>
        var socket = io();
    </script>
</head>
<body>
<h1>Hello Socket</h1>
</body>
</html>



via rut_0_1

No comments:

Post a Comment