Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to create an async function from a string in node js

// Shim for allowing async function creation via new Function
const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;

// Usage
const fetchPage = new AsyncFunction("url", "return await fetch(url);");
fetchPage("/").then(response => { ... });
Source by davidwalsh.name #
 
PREVIOUS NEXT
Tagged: #create #async #function #string #node #js
ADD COMMENT
Topic
Name
7+8 =