It does not get deleted but the variable of that contract is deleted. In order to preserve the variable of the contract before you exit the geth console, you can store the variable with corresponding ABI interface and address of the contract in web3js. Example code in node.js:
var http = require('http');
var Web3js = require('web3');
var web3 = new Web3js("ws://localhost:8546");
var server = http.createServer((req,res)=>{
res.statusCode = 200;
res.setHeader('Content-Type','application/json');
// Contract receives ABI interface and address
// Then contract is passed to greeter variable
var greeter = new web3.eth.Contract([
{
"constant": false,
"inputs": [],
"name": "kill",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "greet",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "_greeting",
"type": "string"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
}
], "0x5c6aa1573b32eb75bf516b6d1de1a5a27fadc111"); // <-- this is the address
greeter.methods.greet().call().then((result) => {
console.log(result);
res.end(result);
});
});
server.listen(8080, () => {
console.log('alhamdulillah');
});