Skip to content

Instantly share code, notes, and snippets.

@srele96
Created July 26, 2022 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srele96/3441d42c1380ea0f161d54fa730bb2a8 to your computer and use it in GitHub Desktop.
Save srele96/3441d42c1380ea0f161d54fa730bb2a8 to your computer and use it in GitHub Desktop.
Return JavaScript code from the server
app.get('/js-code', (req, res) => {
res.send(`
console.log(
'Hi there! A script <script src="js-code"></script> will run me'
);
function iCanDoAnything() {
// i can add an element
const body = document.getElementsByTagName('body')[0];
const h1 = document.createElement('h1');
h1.innerText = 'Daayum! I really can do anything.';
body.appendChild(h1);
}
iCanDoAnything();
`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment