I am trying to create a NodeJS application using Elasticsearch
here is my code
<!DOCTYPE html>
<script src="../bower_components/elasticsearch/elasticsearch.js"></script>
<script>
function esPinger() {
var elasticsearch = require('elasticsearch');
var client = elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
client.ping({
// ping usually has a 3000ms timeout
requestTimeout: Infinity,
// undocumented params are appended to the query string
hello: "elasticsearch!"
}, function (error) {
if (error) {
console.trace('elasticsearch cluster is down!');
} else {
console.log('All is well');
alert("YAY");
}
});
}
</script>
<html>
<head>
<title>NodeJS Starter Application</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="stylesheets/style.css">
</head>
<body>
<center>
<button onclick="esPinger()">Ping ES</button>
</center>
</body>
</html>
i installed the elasticsearch client as
npm install elasticsearch
and also
bower install elasticsearch
in my project folder, i can see that there is a bower_componenets folder that has all of the .js files for elasticsearch, including elasticsearch.js
now, when i run my page and click on the button, i get
Uncaught ReferenceError: elasticsearch is not defined
any idea why? am i missing some configuration?
for reference, here is what my project structure looks like
Edit
Here is what i see in the inspect element console
how can it not get the library!


Node.JS is a "server-side" technology, not a "browser" technology.
Thus, Node-specific calls, like:
do not work in the browser.