labelle
labelle

Reputation: 450

Import config.js file in another file

I am trying to create a config file in js for all my keys. The problem is that i am not able to export and export the file. Here is the code and the error:

config.js:

export const mailchimpKey ='KEY'

app.js:

//jshint esversion: 6
const config = require('./config');

I have the folowing error when starting my node server:

C:\Code\boootstrap\boootstrap\src\newsletter\config.js:1
(function (exports, require, module, __filename, __dirname) { export const mailchimpKey ='KEY'
                                                          ^^^^^^

SyntaxError: Unexpected token export
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
[nodemon] app crashed - waiting for file changes before starting...

I read somewhere that I need babel set up to use import/export. Is that true? I tried installing this but not sure I set it up well

Upvotes: 1

Views: 6407

Answers (1)

Schwarz54
Schwarz54

Reputation: 1004

Can you try this:

module.exports={
   mailchimpKey:'KEY'

}

Instead of your code in config.js

Upvotes: 4

Related Questions