javascript - JS: Correct require syntax instead using import -
normaly i'm using es6 syntax import things file:
target.js
import { articles } '/imports/fixtures.js' console.log(articles.main)
fixtures.js
export const articles = { main: { _id: '1234', title: 'anything' } }
now need use fixtures.js file in testing modules, needs require syntax.
but not work:
var { articles } = require('/imports/fixtures.js')
what correct syntax this?
destructuring assignement recent feature, if version of javascript (i guess of nodejs) prior es2015, use:
var articles = require('/imports/fixtures.js').articles
n.b: nodejs supports of desctructuring assignment start v6.
Comments
Post a Comment