Create tar file from files in a particular directory

I need to use nodejs to create a tar file that isn't encompassed in a parent directory.

For example, here is the file system:

/tmp/mydir
/tmp/mydir/Dockerfile
/tmp/mydir/anotherfile

What I'm looking to do is the equivalent to this:

cd /tmp/mydir
tar -cvf archive.tar *

So, when I extract archive.tar, Dockerfile will end up in the same directory I execute the command.

I've tried tar.gz and a few others, but all the examples are compressing an entire directory, and not just files.

I'm doing this so I can utilize the Docker REST API to send builds.

tar -C /tmp/mydir -cvf archive.tar . should do it.

Use tar.gz module. Here is a sample code

var targz = require('tar.gz');
var compress = new targz().compress('/path/to/compress', '/path/to/store.tar.gz',
function(err){
         if(err)
         console.log(err);
         console.log('The compression has ended!');
});

For more options, visit the documentation page.