Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » OM2M » Uncaught TypeError: net.Socket is not a constructor
Uncaught TypeError: net.Socket is not a constructor [message #1850380] Mon, 28 February 2022 13:44
Cloudy tech is currently offline Cloudy techFriend
Messages: 1
Registered: February 2022
Junior Member
I use browserify to let me use require() in my javascript code but it generates code that contains net.Socket() which give Uncaught TypeError: net.Socket is not a constructor. in the browser is there any solution for that? node version v14.17.4 browserify 17.0.0 this is my main code

tryjson.js

const axios = require('axios');
const InsertToDataBase = require("./InsertToDataBase");
const username = 'admin'
const password = 'admin'
const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')
const urlLAMP_0 = 'http://127.0.0.1:8282/~/mn-cse/mn-name/LAMP_0/DATA/la'
const urlLAMP_1 = 'http://localhost:8282/~/mn-cse/mn-name/LAMP_1/DATA/la'
function getDataLAMP_0(){
  axios.get(urlLAMP_0, {
    headers: {
      'Access-Control-Allow-Credentials': 'true',
      'Access-Control-Allow-Origin':'*',
      "X-M2M-RI":"OM2M-webpage",
      'Authorization': `Basic ${token}`,
      'Accept': 'application/json',
      'mode': 'cors',
      'credentials': 'include',
      }
  })
  .then(function(response) {
        document.getElementById("rn0").textContent = response.data['m2m:cin'].rn;
        document.getElementById("ty0").textContent = response.data['m2m:cin'].ty;
        document.getElementById("ri0").textContent = response.data['m2m:cin'].ri;
        document.getElementById("pi0").textContent = response.data['m2m:cin'].pi;
        document.getElementById("ct0").textContent = response.data['m2m:cin'].ct;
        document.getElementById("lt0").textContent = response.data['m2m:cin'].lt;
        document.getElementById("st0").textContent = response.data['m2m:cin'].st;
        document.getElementById("cnf0").textContent = response.data['m2m:cin'].cnf;
        document.getElementById("cs0").textContent = response.data['m2m:cin'].cs;
        document.getElementById("con0").textContent = response.data['m2m:cin'].con;
        return response;
  })
  .then((response) => {
    var rn0 = response.data["m2m:cin"].rn;
    var ty0 = response.data["m2m:cin"].ty;
    InsertToDataBase.insertdatatolamp0(0,1);
  })
}


function getDataLAMP_1(){
  axios.get(urlLAMP_1, {
    headers: {
      'Access-Control-Allow-Credentials': 'true',
      'Access-Control-Allow-Origin':'*',
      "X-M2M-RI":"OM2M-webpage",
      'Authorization': `Basic ${token}`,
      'Accept': 'application/json',
      'mode': 'cors',
      'credentials': 'include',
      }
  })

  .then(function(response) {
        document.getElementById("rn1").textContent = response.data['m2m:cin'].rn;
        document.getElementById("ty1").textContent = response.data['m2m:cin'].ty;
        document.getElementById("ri1").textContent = response.data['m2m:cin'].ri;
        document.getElementById("pi1").textContent = response.data['m2m:cin'].pi;
        document.getElementById("ct1").textContent = response.data['m2m:cin'].ct;
        document.getElementById("lt1").textContent = response.data['m2m:cin'].lt;
        document.getElementById("st1").textContent = response.data['m2m:cin'].st;
        document.getElementById("cnf1").textContent = response.data['m2m:cin'].cnf;
        document.getElementById("cs1").textContent = response.data['m2m:cin'].cs;
        document.getElementById("con1").textContent = response.data['m2m:cin'].con;
  })
}
getDataLAMP_0();
getDataLAMP_1();
setInterval(getDataLAMP_0,100);
setInterval(getDataLAMP_1,100);


InsertToDataBase.js from:

const {Client} = require('pg')
const client = new Client({
    user:"postgres",
    password:"admin",
    host:"localhost",
    port:"5432",
    database:"postgres",
})
function insertdatatolamp0(rn0,ty0){
client.connect()
.then(()=>console.log("connected successfuly"))
.then(()=>client.query("insert into lamp0 values ($1,$2)",[rn0,ty0]))
.catch(e=> console.log(e))
.finally(()=> client.end())
}
module.exports = { insertdatatolamp0 };


Previous Topic:Semantic Descriptor
Next Topic:How can I use MongoDB with OM2M
Goto Forum:
  


Current Time: Fri Apr 26 11:40:15 GMT 2024

Powered by FUDForum. Page generated in 0.02896 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top