AdminJS는 3가지 프레임워크를 지원한다
npm i adminjs @adminjs/express -S
npm i express express-formidable -S
const express = require('express');
const AdminJS = require('adminjs');
const AdminJSExpress = require('@adminjs/express');
const app = express();
const port = 3000;
const adminJs = new AdminJS({
databases: [],
rootPath: '/admin',
})
const router = AdminJSExpress.buildRouter(adminJs);
app.use(adminJs.options.rootPath, router);
app.listen(port, () => {
console.log(`listening at http://localhost:${port}`);
});
localhost:3000/admin 으로 접속 해보면
관리자 대시보드가 잘 나오는 것을 확인 할 수 있다!
npm i @adminjs/sequelize -S
app.js
const express = require('express');
const AdminJS = require('adminjs');
const AdminJSExpress = require('@adminjs/express');
const AdminJSSequelize = require('@adminjs/sequelize'); // 추가
const app = express();
const port = 3000;
const adminJS = new AdminJS({
databases: [],
rootPath: '/admin',
})
AdminJS.registerAdapter(AdminJSSequelize); // 추가
const router = AdminJSExpress.buildRouter(adminJS);
app.use(adminJS.options.rootPath, router);
app.listen(port, () => {
console.log(`listening at http://localhost:${port}`);
});
실행 방법
npm run sequelize db:create
으로 실행 하면 되는데
이러한 오류가 발생한다면
package.json
에서 scripts 부분에
"sequelize": "sequelize"
를 추가한 뒤 다시 npm run sequelize db:create
을 해주면 된다