The server

'use strict';

const fs = require('fs');
const net = require('net');
const filename = process.argv[2];

const server = net.createServer((connection) => {
	console.log('Subscriber connected.');

	connection.write(JSON.stringify({
		type: 'watching',
		file: filename,
	}) + '\n');

	let watcher = fs.watch(filename, () => {
		connection.write(JSON.stringify({
			type: 'changed',
			file: filename,
			timestamp: Date.now()
		}) + '\n');
	});
		
	connection.on('close', () => {
		console.log('Subscriber disconnected.');
		watcher.close();
	});

});

if (!filename) {
	throw new Error('No target filename was specified.');
}

server.listen('5432', () => {
	console.log('Listening for subscribers');
});

The client

"use strict";

const net = require('net');
const client = net.connect({port: 5432});

client.on('data', (data) => {
	let message = JSON.parse(data);

	if (message.type === 'watching') {
		console.log(`Now watching '${message.file}' for changes...`);
	} else if (message.type === 'changed') {
		const friendlyDate = new Date(message.timestamp).toISOString();
		console.log(`File '${message.file}' changed: ${friendlyDate}`);
	} else {
		throw new Error(`Unrecognized message type: ${message.type}`);
	}
});