First of all you should login your eth account like below
const keystore = fs.readFileSync("your keystore path", "utf8");
var activeAccount = web3.eth.accounts.decrypt(keystore, password);
Now you can sign and broadcast your transaction. You must encode your swap message and add your tx's data field. Don't miss eth amount how many want to swap with token.
var swap = UniswapV2Router02Contract.methods.swapExactETHForTokens(amountOutMin, [WETH[activeChain].address, token.address], activeAccount.address, timeStamp)
var encodedABI = swap.encodeABI()
var tx = {
from: activeAccount.address,
to: UniswapV2RouterAddress,
gas: 200000,
data: encodedABI,
value: ethAmount
};
var signedTx = await activeAccount.signTransaction(tx)
web3.eth.sendSignedTransaction(signedTx.rawTransaction)
.on('transactionHash', function(hash){
})
.on('confirmation', function(confirmationNumber, receipt){
})
.on('receipt', function(receipt){
})
.on('error', function(error, receipt) { // If the transaction was rejected by the network with a receipt, the second parameter will be the receipt.
console.error("Error:", error, "Receipt:", receipt)
});
I also answered same question at here