🌻 Node.js tutorial to make Google Forms within an hour | Hana Forms Public (a subsystem for users to enter their answers) [demo video available]
This article describes how to make a online form creator like Google Forms in Node.js. The online form creator implemented in this article consists of the following two subsystems.
- Hana Forms Public: a subsystem for users to enter their answers
- Hana Forms Admin: a subsystem for users to manage forms
This article covers Hana Forms Public. See Hana Forms Admin for the other subsystem. The resources related to this artice are as follows:
The workflow is as follows:
- Preparing for the database
- Preparing for coding
- Coding
- Operation check
Run the following command in the terminal to prepare for the database.
create database hana_forms charset utf8;
create user hana_forms@localhost identified by 'password';
grant all privileges on hana_forms.* to hana_forms@localhost;
Run the following command in the terminal to prepare for coding.
mkdir HanaForms
cd HanaForms
npm init -y
npm install --save dotenv ejs express morgan mysql2 sequelize
touch .env api-initialize.js api-validate.js api-submit.js fixture.js main.js model.js static-js-input.js validate.js view-finish.ejs view-home.ejs view-input.ejs
Open .env in the editor and enter the following content.
Open main.js in the editor and enter the following content.
Open view-home.ejs in the editor and enter the following content.
Open view-input.ejs in the editor and enter the following content.
Open view-finish.ejs in the editor and enter the following content.
Click to go to view-finish.ejs
Open model.js in the editor and enter the following content.
Open fixture.js in the editor and enter the following content.
Open static-js-input.js in the editor and enter the following content.
Click to go to static-js-input.js
Open validate.js in the editor and enter the following content.
Open api-initialize.js in the editor and enter the following content.
Click to go to api-initialize.js
Open api-validate.js in the editor and enter the following content.
Click to go to api-validate.js
Open api-submit.js in the editor and enter the following content.
Run the following command in the terminal to create tables and insert records.
node -r dotenv/config fixture.js
Run the following command in the terminal to start the server.
node -r dotenv/config main.js
Access http://localhost:3000/form/1234abcd/ in the browser.
Fill out the form and click the submit button.
Check that the finish page is displayed.
We have implemented a subsystem like the Google Forms answer page that dynamically generates a form based on a database record. However, the implemented system has been simplified for the tutorial. In order to get closer to Google Forms, it is necessary to provide the following functions.
- Display of images and videos
- File upload
- Sending reception email
- Theme setting
In addition to adding features, you need to address the following:
- Improving user experience
- Improving security
- Improving operability
- Improving accessibility
One example of improving user experience is the real-time display of validation error messages. For that, it is necessary to perform various processing with JavaScript on the front end, and in that case, module bundler such as webpack may be useful.
One example of improving security is setting the Content Security Policy. You can use Helmet middleware to automatically add security HTTP headers to your Express router.
One example of improving operability is log collection. Winston is a well-known node collection library for Node.js.
One example of improving accessibility is setting the aria attribute. W3C's WAI-ARIA Overview page is very helpful for accessibility information, including the aria attribute.
Read the Hana Forms Admin article to learn how to create a subsystem for users to manage their forms. If you have any opinions or impressions, please feel free to comment. Thank you for reading!