jsreport® is a customizable and open reporting tool that runs on node.js. It allows you to create various reports in various formats like pdf, excel, XML or HTML. The main idea of jsreport is to let users define reports without lame designers but instead by using code, mostly HTML and javascript templating engines. They offer a cloud-hosted solution called jsreport online. However, this post aims at getting a jsreport setup on a ubuntu server.
This depends on the kind of load that expect on the server. A small server with 2 GB of RAM is quite sufficient to handle most of the requirements. If you find that the server is not coping with the load then you can easily set up a bigger server and import all the templates using the GUI provided.
The only software requirement is node.js > 8.9 and npm > 6.x
We will use the node.js ver 12.14 LTS for this post which is the current latest LTS version available. To install use the following code
1 2 |
>> curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - >> sudo apt-get install -y nodejs |
To install JSReports and configure a directory, run the following commands (May have to be run as root).
NOTE: While configuring choose username, password, port and keep it an HTTP web server and default port to be 5488.
1 2 3 4 5 |
>> npm install jsreport-cli -g >> mkdir jsreportapp >> cd jsreportapp >> jsreport init >> jsreport configure |
If you wish to generate PDF reports, you need to install chrome-pdf dependencies. Use the following command to install them. You may have to run them with sudo
1 2 3 4 5 |
>> apt-get install -y libgconf-2-4 >> wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - >> sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' >> apt-get update >> apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst --no-install-recommends |
You can start the server using the following command from inside the jsreport
directory created during installation
1 |
>> jsreport start |
Now just go to the URL http://<host>:5488
and you should be able to use the username and password set during the configuration stage to login and start using the jsreport platform.
To make this run in the background you can use a tool like pm2
. To set up and use pm2 follow the commands below from the jsreport
directory
1 2 |
>> npm install pm2 -g >> pm2 start server.js |
To use a custom domain to access the jsreport server, you can use nginx
as the proxy server to serve the node.js
app. Install nginx
using the following command
1 |
>>apt-get install nginx |
create a config file similar to the following format. Add your domain name in the server_name
setting
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
server { listen 80; server_name <domain_name>; location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_connect_timeout 10; proxy_read_timeout 120; proxy_pass http://127.0.0.1:5488/; } } |
Restart nginx service
1 |
>> service nginx restart |
The jsreport server should now be accessible using your domain_name
If you have any suggestions or improvements then please comment.