I'm trying to setup a Node.js
server with socket.io
. I'm using the latest template given by WebStorm
template.
My step is first add socket.io to my language and framework - Node.js and NPM. Here is my setting
Then in my "bin/www" I add the below
var io = require('socket.io')(server)
And add this to bottom of the bin/www file (after server has start listening)
io.on("connection",(socket)=>{
console.log("user connected" + socket.id)
})
Then I modify my index.jade as below
extends layout
block content
h1= title
p Welcome to #{title}
li what the ul1
li what the ul2
script.
src="/socket.io/socket.io.js"
script.
var socket = io();
Run the server. visit the page and this is what I get
I get the error
Uncaught ReferenceError: io is not defined
at localhost/:1
Anyone know what wrong with my implementation?
I guess your browser can't find the library. You could include it by adding
to your file.