sitelink1  
sitelink2  
sitelink3  
sitelink4  
extra_vars4  
extra_vars5  
extra_vars6  

json데이터 배열값을 정적인 데이터 파일로 정의하고 이를 데이터로 읽어들여 비즈니스 코드에서 사용하고자 했다

node.js 에서는 module.export 키워드를 사용하여 데이터를 export 했는데

ES6 에서는 문법이 다르다 (bixby js runtime v2 에서의 export function 비교)

그래서 node.js 와 ES6 에서의 사용 차이를 코드로 비교해 보았다

 

1. node.js

hotels.js 파일 정의

module.exports = [

  {

    name: "Best Eastern Hotels and Resorts",

    rating: 4.5,

    lowRate: {

      currencyType: {

        currencyCode: 'USD'

      },

      value: 160.00

    },

    location: {

      longitude: -121.890735,

      latitude: 37.334282,

    },

    reviewCount: 15923,

    images: [

      { url:"/images/hotel-1.jpg"},

      { url:"/images/hotel-2.jpeg"},

      { url:"/images/hotel-3.jpeg"},

      { url:"/images/hotel-4.jpeg"},

    ],

    amenities: [

      'Wifi',

      'Spa',

      'Swimming Pool',

      'Kid-friendly'

    ]

  }

]

 

그리고 import 코드

const data = require('./lib/hotels.js')

 

 

2. ES6

hotels.js 파일 정의

export default {

  getHotels() {

    return [

      {

        name: "Best Eastern Hotels and Resorts",

        rating: 4.5,

        lowRate: {

          currencyType: {

            currencyCode: 'USD'

          },

          value: 160.00

        },

        location: {

          longitude: -121.890735,

          latitude: 37.334282,

        },

        reviewCount: 15923,

        images: [

          { url:"/images/hotel-1.jpg"},

          { url:"/images/hotel-2.jpeg"},

          { url:"/images/hotel-3.jpeg"},

          { url:"/images/hotel-4.jpeg"},

        ],

        amenities: [

          'Wifi',

          'Spa',

          'Swimming Pool',

          'Kid-friendly'

        ]

      }

    ]

  }

}

 

그리고 import 코드

import data from './lib/hotels'

var hotels = data.getHotels();

console.log(hotels[0].name);

 

 

위와 같은 차이만 알게 되었다

ES6 에서 좀더 아름답게 데이터 파일을 export, import 하고 싶었지만 이쯤에서 조사를 마쳤다