ES6を使ったNode.jsのモジュール間のやりとり
node.jsを使ったアプリ作成の動画学習でモジュール間のデータのやりとりを学んだので備忘録としてのせます。
MVCを使用して
ModelがSearch.js
ViewがsearchView.js
Controllerがndex.js
として作成していく予定。
※下記はモジュールでのデータのやりとりのテストをしたもの
JS index.js**
import str from './models/Search'; // import { add as a, multiply as m, ID } from './views/searchView'; import * as searchView from './views/searchView'; // console.log(`Using imported functions! ${a(ID, 2)} and ${m(3, 5)}. ${str}`); console.log(`Using imported functions! ${searchView.add(searchView.ID, 2)} and ${searchView.multiply(3, 5)}. ${str}`);
JS Search.js **
export default 'I am exported String.;'
JS searchView.js **
export const add = (a,b) => a + b; export const multiply = (a, b) => a * b; export const ID = 23;