The snippet below will look inside directory /inputdir and archives the sub-directory called mydirectorywithfiles. The resulting tar file is written to /outdir/mytarfile.tar.gz.
import tar from 'tar';
await tar.c({
gzip: true,
cwd: '/inputdir',
file: '/outdir/mytarfile.tar.gz'
}, ['mydirectorywithfiles']);