A simple Node application that emulates DuckDuckGo-style Bangs (search engine shortcuts).
The main script search.js
works as follows:
- exposes an API endpoint
/search
that accepts a single parameterq
from HTTP GET calls; and - parses
q
to determine whether there is a prefixing or affixing “bang” string (defined as a space-delimited string comprising of a leading letterv
followed by a sequence of alphanumerics) and —- if there is exactly one bang string as defined, looks up it with the leading
v
truncated, against theuser.js
file, which is an array of pairingt
andu
keys —- if there is a matching
t
key, navigates the browser to the URL in the pairingu
key, with its substring{{{s}}}
substituted withq
, truncated of the bang string; otherwise - navigates the browser to DuckDuckGo with the parsed bang string and search query, so that it can be matched against DuckDuckGo’s full catalog of bangs (available at https://duckduckgo.com/bang.js); or
- if there is a matching
- if there are multiple bang strings, follows Step 2(i) with the first treated as the bang string; or
- if there is not any bang string, navigates the browser to Google (anonymously proxied by using DuckDuckGo’s
!g
bang) with theq
as the search query.
- if there is exactly one bang string as defined, looks up it with the leading
You can define your bang strings in user.json
following the template below:
[
{
"t": "exampleBangString",
"u": "https://search.example.org/subpath/?query={{{s}}}"
},
// omitted
]
You can run the script locally with
node .
and find it at localhost:3000.
Or, you can deploy the repo to Vercel for free by clicking the button below.
A preview deployment is available at https://vbang2.vercel.app/. It is recommended to deploy your own instance.
Note: You may want to set the forked repo as private and select an obscure or protected URL for better privacy, especially if you want to save bangs that redirect to confidential or paywalled locations.
Of course, you can also use any cloud service that supports the depolyment of Node.js code, such as fly.io, Cloudflare Worker, etc.
The project is made as a demo for an upcoming member-only post at SSPAI Prime (https://sspai.com/prime/explore). If you find this useful, please consider purchasing a subscription as a form of support. Thanks.