<aside> 🧑🏻‍🏫 프로젝트에 추가적으로 환경 설정을 하고 싶을 때 package.json 과 같은 위치인 루트 경로에 **"next.config.js"**라는 이름으로 설정파일을 추가하고 활용합니다.

</aside>

어떤 옵션이 있나?


실습 - 개발 모드에 따라 API 분기하기


const env = process.env.NODE_ENV;

switch (env) {
	case 'development':
		API_URL = '<http://localhost:8080>;
		break;
	case 'staging':
		API_URL = '<https://stg.api.evereathing.com>';
		break;
	case 'production':
		API_URL = '<https://api.evereathing.com>';
		break;
	default:
		API_URL = '<https://api.evereathing.com>';
}

module.exports = {
	env: {
		API_URL
	}
};
"scripts": {
	"dev": "next",
	"build:staging": "NODE_ENV=staging next build",
	"build": "next build",
	"start": "next start -p 80"
},
// utils/config.ts
export const API_URL = process.env.API_URL;
// API_URL 사용 예제
import { API_URL } from 'utils/config';

//생략
fetch(`${API_URL}/users`).then().then();