Since you are trying to do this from the command line, if you are on a Mac or Linux first install Nodejs by downloading the binaries from the nodejs org site, (should not be too dissimilar on windows). Create a project folder where you'll run commands and install Nodejs modules.
Go to your project folder from the terminal and type:
npm install --save stellar-sdk
This will install your dependencies in a new folder named node_modules. Note that npm stands for Node Package Manager and it will be installed when you install Nodejs. The --save
option is to instruct Nodejs to write the dependency name in the package.json file. Don't worry about it if you're not a developer.
Now create a file with .js
extension and save it in your project folder after copying/pasting this code:
const StellarSdk = require('stellar-sdk');
var pair = StellarSdk.Keypair.random();
var keys = {};
keys.secret = pair.secret();
keys.public = pair.publicKey();
console.log(keys);
Assuming you named this file myStellarKeyPairGenerator.js
you can run the code above by typing in the console:
node myStellarKeyPairGenerator.js
This will print your key pair on the terminal console. The chances someone could have generated the same key pair are considered so unlikely in your lifetime you don't actually need to validate and create a real account on the Stellar network itself. If you want this account to actually exist on the Stellar network you must send Lumens to the public address you've generated.
Make sure to save those keys and optionally encrypt the secret key (not a hash from which you can't derive you key) with a password you'll remember especially if you print them out on paper for cold storage.