DEV Community

Evanderson Vasconcelos de Souza
Evanderson Vasconcelos de Souza

Posted on

How to use the syntax import/export on NodeJS

Hey devs, Wellcome on my first post in DEV Community and sorry that my English, because is don't very good ok?

Let's go!

In this post I go to teach you how to use the syntax import/export of simple way using the module Sucrase.

  • First step: You need to import the modules using 'npm install sucrase nodemon -D' or 'yarn add sucrase nodemon -D';

  • Second step: You need to create a file of configuration 'nodemon.json' and inside him you need to write these lines:

{
"execMap": {
"js": "sucrase-node"
}
}

  • Third step: In file 'package.json' you need to create the field 'scripts' like this:

"scripts": {
"dev": "nodemon PATH_TO_FILE_MAIN"
}

After that you can already use the syntax, see some ways it should stay:

BEFORE:
const express = require('express')

AFTER:
import express from 'express'

BEFORE:
const express = require('express')
const routes = express.Router()

AFTER:
import { Router } from 'express'

BEFORE:
module.exports = routes

AFTER:
export default routes

And then it's very easy? Did you like this post? comment in below ok, have a nice day.

Top comments (1)

Collapse
 
lmjsprogrammer profile image
Vladimir Mironov

Thanks!