Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

jetonk/nodejs-es6-import

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NodeJS/ExpressJS ES6 import class

Do you get SyntaxError: Unexpected token import when you try to use import keyword? : You are in the right place.

This is a minimal setup Node with Express importing ES6 class in a ES6 way using import keyword

  • index.js - Main file where we have imported express and defined the routes
  • services/MainService.js - ES6 Class with one method get() which handles the route /
  • app.js - Here happens the magic in-order to enable importing the ES6 Classes using import keyword

Use cases in this boilerplate/project

Instead of doing

var express = require("express");

We have used import keyword

import express from 'express';

Importing the MainService Class import MainService from './services/MainService'; from the index.js

Releases

No releases published

Packages

No packages published
Morty Proxy This is a proxified and sanitized view of the page, visit original site.