Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import a JS file in another JS file in ES6?

I have got this node server and a bunch of JS classes in my js directory. I want to create a file called "exports.js" that exports all the classes required by server (using exports.Classname = class notation). However, the problem is that exports.js doesn't have access to the classes. I was wondering what's the correct syntax for importing the whole ES6 class in another file. So far I have tried following with no luck:

//I want to import User class from User.js
import "./User.js"; 
import "User";
import "./User";

Any help would be much appreciated.

Note: Not that it makes any difference but please note that I am using Babel transpiler.

like image 904
fur866 Avatar asked Dec 17 '16 00:12

fur866


1 Answers

// user.js
class user{
    ...
}
export default user

// another js
import user from './user.js'
like image 111
Alessia Avatar answered Oct 09 '22 21:10

Alessia