Specifying ES6 “import” and CommonJS, require()

Ryan Kim
Oct 28, 2020

I got very small issues when I had a side project as usual.

I think I am still not so skillful to use modern javascript, ES6 in my project.

I have used ES6 syntax in very limited cases, such as arrow function, restructuring assignment, backtick, rest parameter, and etc.)

require method use in Common JS, line 9 is working without a problem.

I have not any errors when I am using the “require” method because requires is embedded syntax in node.js itself, so there is no trans compiling issue.

I changed these codes with modern JS, you can see the entire process setting in here

I have errors when I use modern JS, though.

the main error occurred in line 11, routes folder.

all codes are working well except line 11.

why did the error happen?

I deeply considered why 500 errors occurred that the server-side can not process the request from the client-side whereas the client sends the request well.

I finally found the reason here, the export file, routes/index.js can not send googleMapsClient object when the “route” function exported.

Ignore some Korean annotation in the codes

At first, I insert the “googleMapsClient” variable in each router but this way reduces the readability of the codes.

You see below:

see line 21 & 36 in the codes
now it’s working!

I have not solved better ways than the above one.

If anyone has feedback, please leave comments.

Thanks

Ryan

Reference

Stackoverflow

--

--