Before explaining what features we are attempting to experiment with, there are a few notable modifications to the node application that are required to run it.
This is a simple plain node application with two subtle but notable additions.
- I am using the
--experimental-modules
flag when running the project so i can use standardexport
andexport default
for exporting from a module. Allows us to useimport <file> from "<path>"
syntax with js modules. - I've modified package.json to include the line
"type": "module"
These modifications allow us to use the newer import/export syntax. Also be aware that using import for local modules in this context requires the file extension like so:
// notice the .js at the end of the import statement of this local
// module. Dependencies installed via npm do not require the .js
import CoffeeMachine from "./utils/private-class-members.js";
- Asynchronously import another module that returns a promise
- Using
#
for private props within classes - Uses
Promise.allSettled([...promises])
instead ofall()
- Uses
Promise.any([...promises])
instead ofrace()
- Use nullish coalescence operator
- Use the Elvis operator
Clone the project & then cd into the directory
$ git clone git@github.com:AndrewJHart/es10-features-in-node-13.git
$ cd es10-features-in-node-13
This project only has one dependency, node-fetch
so install it
npm install
note: make sure you are using at least node version
12.13.0
.
To run the project is simple. To obviate having to run the script with
the --experimental-modules
flag every time, i've added a script in
package.json that uses the experimental flags.
just execute this in the project directory:
$ npm run start
That's all folks. I'll be adding new things later when i have time just to test them.