Use a regular expression to easily chunk a string:
conststring='68656c6c6f20776f726c6421';constchunks=string.match(/.{2}/g);// ['68', '65', '6c', '6c', '6f', '20', '77', '6f', '72', '6c', '64', '21']consthex=chunks.map((chunk)=>Number(`0x${chunk}`));constbuf=Buffer.from(hex);// <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64 21>console.log(buf.toString());// 'hello world!'