Skip to content

Instantly share code, notes, and snippets.

@underoot
Created November 14, 2018 20:04
Show Gist options
  • Save underoot/d8c726fc5e2707d2d9a3db0e33f2ce55 to your computer and use it in GitHub Desktop.
Save underoot/d8c726fc5e2707d2d9a3db0e33f2ce55 to your computer and use it in GitHub Desktop.
Async Template Tag
'use strict';
const got = require('got');
const express = require('express');
const app = express();
const html = (body) => ({
fillSearch: (value) => html(body.replace(
'id="text"', `id="text" value="${value}"`
)),
toString: () => body
});
const search = async (parts) => (
html((await got('https://ya.ru')).body).fillSearch(parts.join('')).toString()
);
app
.get('/', async (req, res) => {
res.send(await search`ВВП`);
})
.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment