These days we can use Nodejs for almost anything, be it a simple function, a complex algorithm, or anything that comes to mind. Usually, what we want Nodejs to do happens very quickly, and we don't even have to wait for it to finish.
However, sometimes you are writing a NodeJs code, process, or job that may take a long time to run. For example, you may decide to crawl a website or run a long-running parsing algorithm.
I'm sure almost every developer has, at some point, written a NodeJs code that takes a long time to run. They then had to continuously check the task, wait for it to finish running, and ensure the NodeJs code was working as expected. As you can see, this gets tedious very quickly and wastes time and effort.
One common way to solve this is to track the status of our NodeJs code and send a push notification when the code is done running or when it fails. By doing so, we can leave and forget about the long-running NodeJs code and focus on the important things we need to do, and by the time something happens, we will instantly get a push notification to let us know.
To do so, we can use Palzin Track to track the status of our NodeJs code. Palzin Track is a simple, easy-to-use, robust event tracking and notification system that lets you track your NodeJs code and send push notifications when something happens.
Let's walk you through setting up and using Palzin Track to track the status of our NodeJs code.
Now that we have our account and project setup, we can copy the following code snippet, update the values with your information, and paste it into your code.
Using NodeJs with Axios
var axios = require('axios');
var data = JSON.stringify({
"project": "my-project",
"channel": "crawler",
"event": "Crawling is complete",
"description": "Successfully crawled 1,230 pages.",
"icon": "🔥",
"notify": true
});
var config = {
method: 'post',
url: 'https://api.palzin.live/v1/log',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_TOKEN'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Using NodeJs with Native
var https = require('follow-redirects').https;
var fs = require('fs');
var options = {
'method': 'POST',
'hostname': 'palzin.live',
'path': '/api/v1/log',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_TOKEN'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = \[\];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
var postData = JSON.stringify({
"project": "my-project",
"channel": "crawler",
"event": "Crawling is complete",
"description": "Successfully crawled 1,230 pages.",
"icon": "🔥",
"notify": true
});
req.write(postData);
req.end();
Using NodeJs with Request
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://api.palzin.live/v1/log',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_TOKEN'
},
body: JSON.stringify({
"project": "my-project",
"channel": "crawler",
"event": "Crawling is complete",
"description": "Successfully crawled 1,230 pages.",
"icon": "🔥",
"notify": true
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
Using NodeJs with Unirest
var unirest = require('unirest');
var req = unirest('POST', 'https://api.palzin.live/v1/log')
.headers({
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_TOKEN'
})
.send(JSON.stringify({
"project": "my-project",
"channel": "crawler",
"event": "Crawling is complete",
"description": "Successfully crawled 1,230 pages.",
"icon": "🔥",
"notify": true
}))
.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.raw_body);
});
Palzin Track provides several other features that can be used to simplify your job as a developer. For example, suppose you're working with a team. In that case, you can also add the rest of your team to your Palzin Track project and allow them to see the status of your NodeJs code and receive push notifications when something important happens.
Palzin Track also keeps track of your previous events, so you can see what has happened in the past and search through previous events. We found this to be very powerful when we are working on larger projects and need to see what has happened in the past.
In addition, Palzin Track allows you to create simple dashboards, charts, and graphs that give you more insight into your code and the events you track.
Palzin Track reveals the human stories behind your data. Make user-centric decisions that drive growth.