How to Use the Analog Input Function in JavaScript?

I have an problem that needs to be fixed urgently !

My project is a burglar alarm system. I need a program that compares the value taken by the A0 pin (LDR is connected) with an integer value. Pls can anyone send the code to make that happen with javascript.

This is my code:

var lightIntensity=analogRead(A0);
if(lightIntensity < 125)
digitalWrite(1, ‘HIGH’);

you can use on click as
analogWrite(pin, value)
value can be from 0 to 255

I don’t want to use buttons. I want to create a project where the ldr value decreases it will automatically start the buzzer.

@vinay.hariya Check if this snippet works for you.

var base_url = "";
var api_key = "";
var d_name = "";

function analogRead(pin) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
    //document.getElementById(element_id).innerHTML = xmlhttp.responseText;
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        var obj = JSON.parse(xmlhttp.responseText);
        return obj;

var response = analogRead("A0");
if(response["status"] != "1"){
console.log("Error occurred in getting response");
var ana_val = response["value"];
console.log("This is the analog value:" + ana_val);