Use path.extname to replace extension

Alternative method to replace the extension. Not sure if this method is
buggy is past versions of node.