How to generate timestamp unix epoch format nodejs?

I am trying to send data to graphite carbon-cache process on port 2003 using

1) Ubuntu terminal

echo "test.average 4 `date +%s`" | nc -q0 127.0.0.1 2003

2) NODEJS

var socket = net.createConnection(2003, "127.0.0.1", function() {
    socket.write("test.average "+assigned_tot+"\n");
    socket.end();
});

It works fine when i send data using the terminal window command on my ubuntu. However, i am not sure how to send timestamp unix epoch format from nodejs ?

Grpahite understands metric in this format metric_path value timestamp\n

The native JavaScript Date system works in milliseconds, but otherwise it is "epoch time" the same as UNIX:

Math.floor(new Date() / 1000)

If you can, I highly recommend using moment.js. To get the number of milliseconds since UNIX epoch, do

moment().valueOf()

To get the number of seconds since UNIX epoch, do

moment().unix()

You can also convert times like so:

moment('2015-07-12 14:59:23', 'YYYY-MM-DD HH:mm:ss').valueOf()

I do that all the time.

To install moment.js on Node,

npm install moment

and to use it

var moment = require('moment');
moment().valueOf();

ref