node.js as a webserver for esp8266

1 post / 0 new
Samir Arishy's picture

Offline

Joined: Mar 25, 2017

Replies: 0
node.js as a webserver for esp8266
May 5, 2020 - 12:22am

I am using ESP8266 web server to control GPIO. My Wi-Fi network give it an IP of ....99:3300

And it works...THEN I decided to use node.js ( I am a beginner ) and here it is

<pre 

const http = require('http');

 

const hostname = '192.168.1.99';

const port = 3300;

 

const server = http.createServer((req, res) => {

res.statusCode = 200;

res.setHeader('Content-Type', 'text/plain');

res.end('/5/on');

});

 

server.listen(port, hostname, () => {

console.log(`Server running at http://${hostname}:${port}/`);

});

It does not work...

 

Error: listen EADDRNOTAVAIL: address not available 192.168.1.99:3300

 at Server.setupListenHandle [as _listen2] (net.js:1296:21)

 at listenInCluster (net.js:1361:12)

 at doListen (net.js:1500:7)

 at processTicksAndRejections (internal/process/task_queues.js:85:21)

Emitted 'error' event on Server instance at:

 at emitErrorNT (net.js:1340:8)

 at processTicksAndRejections (internal/process/task_queues.js:84:21) {

code: 'EADDRNOTAVAIL',

errno: 'EADDRNOTAVAIL',

syscall: 'listen',

address: '192.168.1.99',

port: 3300

}

</pre>

my url request gpio 5 to be on ( /5/on) and it is working on the server created by ESP8266

My guess is node.js is trying to "create" an already created server (created by ESP8266 code), but I do not know how to make node.js connect to ALREADY existing web server