Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Run Any Version of a Node Tool with npx


    As node projects evolve, new features are added all the time. This results in different errors or results as you're migrating from one version to another. npx allows you to try out any version you want by simply adding the version number to the project you're using. This lesson covers using the TypeScript compiler through a different versions as async function support was added.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Let's create a TypeScript file that has an async function in it, so async function foo, and then just write that out to an index file, so the entire contents of that file is just async function foo.

    With NPX, I can try out different versions. If I try out 1.6 of TypeScript and then pass in my file, you'll see that I get this specific error saying they're only available with ES6, and it's asking me to specify experimental async functions, so let's try with TypeScript 1.7.

    This time you see we get that first error, but we don't get that second error. That's only because we changed versions of TypeScript, which has change support for async functions over time.

    If we try with a much later version of TypeScript like 2.4, you'll see that it handles the async function just fine, and doesn't throw any errors. If I just try TypeScript without any version number in there, it'll use the latest version, and that won't produce any errors either.

    We can check the output, which would be index.js, and you'll see it compiled it down using that generator polyfill to support async functions. Or if you know that your browser supports async functions, you can always pass in command line arguments like target ES2017, pass in index.ts. Then our output would be the exact same file.