API Rest for books
- NodeJS v14.20.0
- NPM 8.18.0
- MongoDB v4.4.5
- Docker
- Sonarqube
cp .env.example .env
Change variables for .env
APP_PORT=3030
URL_DOMAIN="https://books.proyectosbeta.net"
npm install
npm dev
Needed Docker, Sonarqube and sonar-scanner
docker run -ti -v C:\Users\joseg\repositoriosGit\api-books:/usr/src --link sonarqube newtmitch/sonar-scanner
Method POST: /books --> Add a new book
Method GET: /books/:id --> Return a book by id
Method PATCH: /books/:id --> Update an existing book
Method DELETE: /books/:id --> Delete requested book
Method GET: /books --> Returns all books
http://localhost:3000/api/v1/books/
http://localhost:3000/api/v1/books/62d40cf2d61edb6db30f3cda
http://localhost:3000/api/v1/books/
npm run build
Pm2 is a tool for Node.JS application production environments, basically this tool helps us to launch our application as a daemon service on our server.
npm install pm2 -g
We must create a daemon with PM2 so we stop the server and execute the following command:
pm2 start /home/proyectosbeta/repositoriosGit/api-books/dist/bundle.js --name api-books
We need to configure the server startup script.
pm2 startup
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u proyectosbeta --hp /home/proyectosbeta
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName books.proyectosbeta.net
ServerAlias www.books.proyectosbeta.net
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://127.0.0.1:3030/
ProxyPassReverse / http://127.0.0.1:3030/
ErrorLog "/var/log/apache2/books.proyectosbeta.net.error.log"
CustomLog "/var/log/apache2/books.proyectosbeta.net.access.log" common
RewriteEngine on
RewriteCond %{SERVER_NAME} =books.proyectosbeta.net [OR]
RewriteCond %{SERVER_NAME} =www.books.proyectosbeta.net
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
sudo a2enmod proxy proxy_http
https://books.proyectosbeta.net/api/v1/books
https://books.proyectosbeta.net/api/v1/books/62d40cf2d61edb6db30f3cda
https://books.proyectosbeta.net/api/v1/books