One of the most epic releases lately. Top-Level Await and named imports from CJS modules are now supported in v14.3.0.
Like Deno, itβs now possible to use the await keyword outside of async functions.
Letβs take a look at an example.
We will fetch a random user from a API and say hello.
// hello.js
export const sayHello = (name) => `Hello, ${name}!`;
// index.js
import axios from "axios";
import { sayHello } from "./hello.js";
const { data } = await axios.get("https://api.namefake.com/");
console.log(sayHello(data.name));
Add the type
property in your package.json
file with value of module
.
{
"name": "node-14.3.0",
"version": "0.0.0",
"main": "index.js",
"type": "module",
"dependencies": {
"axios": "^0.20.0"
}
}
Run it with the --harmony-top-level-await
flag.
node --harmony-top-level-await index.js
Output:
Hello, Miss Mellie Mosciski!
When Node finally supports remote imports, then it's a nail in the coffin for Deno.
Cover photo by @cookiethepom on Unsplash
Top comments (10)
Bye deno is a catchy headline, but I think deno has way more goals, like being secure by default, only granting file/network/... permissions to modules that need it, built-in TypeScript support etc.
Programming languages don't die. And just like actual language ( English, Spanish ) the ones you use most comes more naturally to you. Millions of PHP devs are earning more than a guy who's busy finding node vs deno, go vs rust etc. Also if your product grows, you won't be using 1 programming language. Please stop publishing clickbaity articles.
Why is PHP mentioned here βοΈJavaScript of course wont die π
JavaScript is dying. Name one hiring company that isnβt forcing typescript garbage on us
I don't think deno will die cause of this, but, I can guarantee that node will have every use that deno has in the near future, so, at some point, deno Will die because of nodejs updates.
Wow, this is like a slam piece for like no reason. Deno has a lot more to offer than a top level await. Perhaps you could have rephrased this to "Node receives top-level await". Deno is a wonderful language with a lot of use cases that I've used GoLang for in the past instead of node.
This is a completely uninformed article. Native native typescript support, no node-modules, easier bundling...
And like folks have mentioned: Languages don't die...
The appeal of Deno isn't top level await. It's native TypeScript support
Coding native modules using N-API sucks, coding native modules on Rust for Deno has been a breeze. Enforcing typescript is the difference between editors like VS Code being gods or being colored note taking apps.
The thing I like less about Deno is the remote imports, having a (popular) centralized package manager is the only reason Node has become what it's currently today (maybe github with their packages will be a light on Deno, idk yet).
It's not only features, top level await is ridiculously small compared to first-class typescript support. I can code a babel plugin that solve my remote imports in an afternoon but I can't make typescript development in Node more streamlined (at least not in the level Deno is attempting to).
Is first class TypeScript support that important? It still internally compiles to Javascript, though. Also, you can create tsconfig.json and add additional options.
However, among the most important, I think it is security, and web browser like modules (i.e. ditching commonjs).
Anything that lived long enough will suffer from backward compat.
I am still half hearted about not supporting gyp, relying only on web assembly.
Deno's foundation is better than that of Node. Rust Lang is boss