- Create folder for progect
- use command
npm init
- use commans
npm i express --save
- use command
npm i telegraf --save
- use command
npm i bitcoinaverage --save
- use command
npm i fs --save
- create files "server.js", "bot.js" and copy content from git
- create folder "public" and there files "client.js", "ndx.html" and copy content from git
- now in folder vs index.js use command
node server.js
to launch project use node server.js
command in folder vs server.js
Folder "public" is visible for user. There u can find module "client.js", which is for taking info from "nindex.html", creating requests for server and returning info to html to make it visible to user
List of requests in "client.js" and in "server.js"
in client:
fetch('/custom_tikers', {method: 'GET'})
.then(function(response) {
if(response.ok) return response.json();
throw new Error('Request failed.');
})
in server:
app.get('/custom_tikers', (req, res) => {
//res.sendStatus(201);
//console.log(response);
res.send([201, get_extract(name[req.sessionID])]);
});
in client:
fetch('/tiker', {method: 'GET'})
.then(function(response) {
if(response.ok) return response.json();
throw new Error('Request failed.');
})
in server:
app.get('/tiker', (req, res) => {
//res.sendStatus(201);
restClient.getTickerDataPerSymbol('global', tiker + 'USD', function(response) {
var response = Number(JSON.parse(response).last);
//console.log(response);
res.send([201, response]);
});
in client:
fetch('/tg', {
method: 'post',
headers: {'Content-Type': 'application/json;charset=utf-8'},
body: JSON.stringify(targets),
})
in server:
app.post('/tg', (request, response) => {
const tg_id = request.body;
for(var i in tg_id)
{
append(i, tg_id[i], name[request.sessionID]);
}
//console.log(request.body);
response.send(201);
});
in client:
fetch('/get_extra', {
method: 'post',
headers: {'Content-Type': 'application/json;charset=utf-8'},
body: JSON.stringify({1: document.getElementById("tik").value}),
})
in server:
app.post('/get_extra', (request, response) => {
var ti = request.body[1];
get_extract(name[request.sessionID], ti);
//console.log(get_extract(name));
response.send(201);
});
in server:
app.post('/auth', (request, response) => {
name[request.sessionID] = request.body[1];
console.log(name[request.sessionID]);
response.redirect('http://localhost:3000/');
});
in client side auth is in file "authorisation.html"
in server:
app.post('/customsale', (request, response) => {
const tiker = request.body[1];
console.log(tiker);
response.send([3, 201]);
});
in client this shit doesnt work and i have no idea how to fixe it, so i use a buttplug
Geleral difference between app.post and app.get is that app.get doesnt put any info to server, we only request thomething from it, while app.post allows us to put some info to server
function isNumber(n){
return Number(n)=== n;
}
extra_tikers - list of personal tikers wich can be added
function get_extract(name, tik = ''){
if(extra_tikers[name] == undefined){
extra_tikers[name] = [];
}
if(tik != ''){
//console.log(extra_tikers[name]);
extra_tikers[name].push(tik);
}
return(extra_tikers[name]);
}
"append" adds tiker and price to expected
function append(tiker, price, id)
{
if (ticers[tiker] == undefined){
ticers[tiker] = {}
}
if(isNumber(id))
ticers[tiker][price] = id;
else
if(id in users)
ticers[tiker][price] = users[id];
}
Here express start: https://expressjs.com/ru/starter/installing.html
And here hello world example https://expressjs.com/ru/starter/hello-world.html