Chat freely about the open source Javascript projects for ESP8266

User avatar
By EdwardSMaTeresa
#94400 Hi
I have just entered the world of JavaScript and Node.JS. But i know C# quite well. I'm trying to make an Arduino collect some data and send it to my Ubuntu server(rented at DigitalOcean). I'm using an ESP8266 Arduino to make a post request(Arduino wifi module), and i'm sure that that part works.

The problem is, i want to recieve and display the data my Arduino sent on the server. But the JavaScript part does not seem to work (on the server).

Here is the code that the ESP8266 Arduino uses.

include Arduino.h
include ESP8266WiFi.h
include ESP8266WiFiMulti.h
include ESP8266HTTPClient.h

#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;

String ssid = "YourWifiName";
String password = "YourWifiPassword";
String website = "";
String data = "20";

void setup() {

// USE_SERIAL.setDebugOutput(true);


for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);

WiFiMulti.addAP("drach", "a5b4c3d2e1");

void sendData(String data) {
HTTPClient http;
USE_SERIAL.print("Attempting upload to");
http.begin("" + data);
int code = http.POST("Doge");

USE_SERIAL.print("Response code = ");

if ( code > 0 ) { USE_SERIAL.println("Upload succeeded"); }
if ( code == 0 ) { USE_SERIAL.println("Upload failed"); }

void loop() {

USE_SERIAL.println("Waiting for connecting");
if(( == WL_CONNECTED)) {
} else {
USE_SERIAL.println("Connecting faled, trying again");

The way we thought of handling the post request was with JavaScript using the Express and body-parser module. Express has an example on setting the Express module and a get request up. But there is no example of a post request. Link to express's example: Here is the code we ended up with.

var express = require('express');
var bodyParser = require('body-parser');
var app = express();

var urlencodedParser = bodyParser.urlencoded({ extended: false });

app.get('/', function (req, res) {
res.send('Hello World!');
});'/', urlencodedParser, function(req, res){
console.log("Post triggered");

app.listen(3000, function () {
console.log('Example app listening on port 3000!');

Our goal is to receive and log the data which the Arduino sent to our server.

We hope for a nice feedback! Thank you very much.
User avatar
By quackmore
#94404 you'll have to specify the content-type for body-parser to work
this example will work if you add an header with "Content-type: text/plain;" to the POST in your arduino code

Code: Select allconst express = require('express')
const bodyParser = require('body-parser')
const app = express()

app.use(bodyParser.text()) // body-parse will look for 'text' content

app.get('/', (req, res) => {
    res.send('hello world')
})'/', (req, res) => {
    console.log("post triggered")
    res.send('got it')

app.listen(3000, function () {
    console.log('Example app listening on port 3000!');