An important tip while using Node JS

An important tip while using Node JS

As you might already know that import and export statements are not supported natively in nodeJS right now. This is what happens if you try running your server code with import statements:

Screenshot 2020-09-06 at 12.36.43 AM.png

So currently, we use require to do that job of importing node JS modules like express:

const express = require('express');

But now, node has introduced import and export statements in experimental features in versions greater than13.x.x, where you can easily turn them on by two ways:

1) Setting type: "module" in package.json.

Screenshot 2020-09-06 at 12.27.50 AM.png

Now, if you run your server file:

Screenshot 2020-09-06 at 12.28.04 AM.png

2) Saving files with extension.mjs

For example: Save your file with name server.mjs and run it as:

node server.mjs

That will work too.