Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM node:22-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install --omit=dev
COPY . .
RUN npm install
CMD ["npm","start"]
EXPOSE 3000
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Template Repository

- The repository is template setup for nodejs project that have setup of eslint, prettier, eslint+prettier, husky, docker, swagger Api, .gitignore, rules of eslint, separate folder inside src, services and prisma ORM setup.

## Eslint + prettier

- Their is eslint + prettier setup of rules which warn unused variable and noUnd. and reformat code when saved the file.

## husky

- When we try to commit with errors in project or the hook that return before commit will not do commit before task that are written in husky file.

## Docker Setup

- The docker is already setup in project if three or five developers working on same project then they have all to install software, dependency. By using docker you containerize your application and you can easily put on production container.

## Swagger Api

- The swagger api provide documentation of https request.

## src Folder

- There is different folder for controllers, model, routes and service.

## Prisma ORM setup

- Object Relational Model is bridge between database and the javascript language. Model is like language of bridge. Schema is translator language.
`npx prisma init` : For intializing of prisma in project.

`npx prisma migrate dev` : For generating migration of database

### 1. Build the image

```bash
docker build -t nodejs-base-project .
```

---

### 2. Run the container

```bash
docker run -p 3000:3000 --name bookstore-backend nodejs-base-project
```

---

### 3. Verify it’s running

Open:

```
http://localhost:3000/health
```

## Cleanup

Stop container:

```bash
docker ps
docker stop <container_id>
```

Remove container:

```bash
docker rm <container_id>
```

Remove image:

```bash
docker rmi nodejs-base-project
```
5 changes: 4 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import swaggerDocument from './swagger.json' with { type: 'json' };
const PORT = 3000;
const app = express();
app.get('/health', (req, res) => {
res.send({ message: 'Healthy gamers' });
res.send({ message: 'Site is healthy.' });
});
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.listen(PORT);
app.post('/book', (req, res) => {
res.send();
});
2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"ext": "json,js,.env,ts",
"ignore": ["node_modules/", "*.test.js"],
"delay": 1000,
"exec": "node src/server.js"
"exec": "node app.js"
}