LoginSignup
0
1

More than 3 years have passed since last update.

【Express】外部ファイルのコード読み込み

Posted at

はじめに

Expressで外部ファイルに記述した処理を使う方法のメモ。

外部ファイルhogehoge.js

exportsを用いる。

//例1
exports.hello = {
  name: 'Taro',
  age: '39',
}

//例2
exports.bye = function () {
  console.log('Good bye');
}

呼び出す側のファイルindex.js

requireで外部ファイルhogehoge.jsを呼び出す。

const hoge = require('hogehoge.jsのパス');

//例1
console.log(hoge.hello);

//例2
hoge.bye;
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1