Thursday, 3 January 2019

Node.js + Express.js Webserver. Used express-generator 4.16 - Wanna use Socket.io: Where to implement which code-lines?

Hey guys, as in the title said: I am using a Node.js+Express.js Webserver to control my Arduino project via through a web-interface. I would like to get realtime informations from the arduino, shown in the browser. I get those information from the arduino via serialport. For displaying the information in the browser in real time I am planning to use socket.io. I have no issues in getting the tutorial from their website started, unfortunately I used express-generator 4.16 which creates an application skeleton and now I have no idea how to integrate socket.io. All examples I found did not apply for express-generator orwere outdated and assumed different code lines./myapp app.js /bin www package.json /node_modules [about 4,500 subdirectories and files] /public /images /javascripts /stylesheets style.css /routes index.js users.js /views error.pug index.pug layout.pug This is the fresh new skeleton created by the generator. If you want I can post the code of a specific file.I tried to adapt the lines of this tutorial (in a stand alone test app it works great) but in my project I have a problem with var io = require('socket.io')(http); . I guess because http (or the server?) is initialized in /bin/www. I get this error: ReferenceError: http is not defined . I tried some things with module.export but I am new to Node.js and could't figure it out on my own. Can someone tell me how I can fix my issue or tell me which lines of code I need to place where? Or give me some advice so I can figure it out myself? =)​Tell me if you need more input.​best wishes and thank you

Submitted January 03, 2019 at 09:23PM by cablefromthematrix

No comments:

Post a Comment