Build a Responsive Node.js HR Onboarding Packet Service
In this article
This guide walks you through creating a Node.js service that generates responsive HTML onboarding packets for new HR hires. You’ll build an Express server that combines employee data with a mobile-friendly template, producing a single downloadable HTML file that works on any device. By the end, you’ll have a reusable service that can be extended with PDF export or email delivery.
What You'll Need
- Node.js (version 14 or later) installed on your machine
- A code editor (VS Code, Sublime, etc.)
- Basic familiarity with JavaScript and Express
- npm (comes with Node.js)
Step-by-Step
- Initialize your project
Create a new directory and runnpm init -yto generate apackage.jsonfile. Then install Express and a templating engine (we’ll use EJS) withnpm install express ejs. - Set up the server
Createserver.jsand set up a basic Express app. Configure EJS as the view engine and set the views directory: - Create the onboarding packet template
Inviews/packet.ejs, build an HTML template with responsive CSS (using flexbox/grid and media queries). Use EJS tags to inject employee data like name, role, start date, and list of forms. - Define the data structure
Create a sample employee object with fields:name,role,startDate,department,forms(array of form names), andcompanyinfo. Store it in a separate file or in-memory. - Create the route
In your server, add a GET route like/onboarding/:employeeIdthat fetches the employee data (from a database or mock) and renders the template with that data: - Add responsive styling
In the template, use a mobile-first approach: setmeta name="viewport", use fluid widths, and stack sections on small screens. Test with browser dev tools. - Serve the packet as a download
To let HR download the packet, set the content-disposition header to attachment. Useres.setHeader('Content-Disposition', 'attachment; filename=onboarding.html')before rendering. - Test the service
Runnode server.jsand visithttp://localhost:3000/onboarding/1. Open the HTML file on a phone or resize the browser to verify responsiveness. - Add error handling
If employee not found, return a 404 with a friendly message. Wrap route logic in try-catch to handle unexpected errors. - Optional: add PDF conversion
Use a library likepuppeteerto render the HTML to PDF. This is useful for formal distribution.
Common Mistakes
- Forgetting the viewport meta tag – without it, mobile devices render the page as a desktop view.
- Using fixed pixel widths for layout – use percentages or flexbox to adapt to screen size.
- Not escaping user input – use EJS’s
<%= %>to prevent XSS attacks. - Hardcoding data instead of using a database – this makes the service less flexible.
- Ignoring print styles – HR often prints packets; add
@media printrules.
Tips
- Use a CSS framework like Bootstrap or Tailwind to speed up responsive design, but keep it minimal to avoid bloat.
- Organize your templates with partials (header, footer) to avoid duplication.
- Cache employee data if it doesn’t change often – use Redis or in-memory caching.
- Add a “last updated” timestamp to the packet for reference.
- Test with real HR forms to ensure all necessary fields are included.
Troubleshooting
- Page not loading – Check that the server is running and the port is correct. Look for errors in the console.
- Styling looks broken on mobile – Ensure the viewport meta tag is in the
<head>. Also check that media queries are written correctly. - Data not showing – Verify the employee ID exists and that you’re passing the correct data to the template.
- Download not working – Check the content-disposition header and that you’re using
res.download()or setting headers correctly. - EJS errors – Make sure all variables used in the template are defined. Use
<%= %>for output, not<% %>.
Frequently Asked Questions
Can I use a different templating engine?
Yes, you can use Handlebars, Pug, or plain HTML with string interpolation. EJS is just one option that’s easy to learn.
How do I add a PDF download option?
Use Puppeteer to render the HTML to PDF. Install it, then in your route, launch a browser, load the HTML, and generate the PDF.
How can I send the packet via email?
Use a service like Nodemailer. Render the HTML, then attach it as a file or send the HTML content directly in the email body.
Is it secure to expose employee data?
No, you should add authentication and authorization. Use middleware like Passport.js and only allow HR personnel to access the routes.
Can I integrate with an existing HR system?
Yes, you can fetch employee data from your HR database via an API. Modify the route to query your database instead of using static data.
What if I need to include multiple forms?
Store form names in an array and use a loop in the template to render them. You can also link to external forms or embed them.