Using handlebars.js
-
thanks to all, I am a newbe with n8n
@girish @BrutalBirdie this doc indicate that for security reasons, importing modules is restricted by default in the Function-Nodes and that it is possible to lift that restriction by setting the following environment variables:
- NODE_FUNCTION_ALLOW_BUILTIN: For builtin modules
- NODE_FUNCTION_ALLOW_EXTERNAL: For external modules sourced from
n8n/node_modules
directory
So I created a
node_modules
directory in/app/data/
and installed in it the module handlebars with the commandnpm install handlebars
but it doesn't work. I also tried in/app/data/.n8n
directory with the same result. -
@girish you can read this discussion https://community.n8n.io/t/text-templating-node/1965
handelbars is a template system to facilitate the creation of html document pages, https://handlebarsjs.com/
in my case, I want to get information from baserow tables and use n8n to generate reports and send them by mails
-
@jeau there is a env var
NODE_PATH
that tells node where to find additional node modules. So, you can set the variable in/app/data/env
likeNODE_PATH=/app/data/modules
and then in Web Terminal:mkdir /app/data/modules cd /app/data/modules npm install handlebars
Restart the app afterwards.
-
@girish thanks, however I have this errors after passing the command
npm install handlebars
npm ERR! code EROFS npm ERR! syscall open npm ERR! path /root/.npm/_cacache/tmp/2122bb8f npm ERR! errno -30 npm ERR! rofs EROFS: read-only file system, open '/root/.npm/_cacache/tmp/2122bb8f' npm ERR! rofs Often virtualized file systems, or other file systems npm ERR! rofs that don't support symlinks, give this error.
I tried
npm install --prefix /app/data/modules handlebars
but the result was the samehowever, I have already successfully installed handelbars before, but I forgot how to do it
-
@girish I went back to a fresh installation, because I had not checked the changes of the recent updates. This fix allows me to install handelbars. But it still doesn't work, I still get the message
Cannot find module 'handlebars'
with this example.My session:
root@XYZ:/app/data# vi env root@XYZ:/app/data# cat env # Set the logging level to 'debug' export EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONS=true export EXECUTIONS_DATA_SAVE_ON_ERROR=all export EXECUTIONS_DATA_SAVE_ON_SUCCESS=all export N8N_LOG_LEVEL=info export NODE_PATH=/app/data/modules export NODE_FUNCTION_ALLOW_EXTERNAL=handlebars root@XYZ:/app/data# mkdir modules root@XYZ:/app/data# cd /app/data/modules root@XYZ:/app/data/modules# npm install handlebars --cache /tmp/foo npm WARN saveError ENOENT: no such file or directory, open '/app/data/modules/package.json' npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN enoent ENOENT: no such file or directory, open '/app/data/modules/package.json' npm WARN modules No description npm WARN modules No repository field. npm WARN modules No README data npm WARN modules No license field. + handlebars@4.7.7 added 6 packages from 39 contributors and audited 6 packages in 0.834s found 0 vulnerabilities āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā npm update check failed ā ā Try running with sudo or get access ā ā to the local update config store via ā ā sudo chown -R $USER:$(id -gn $USER) /root/.config ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā root@XYZ:/app/data/modules# ls -al total 16 drwxr-xr-x 3 root root 4096 Oct 9 16:25 . drwxr-xr-x 8 cloudron cloudron 4096 Oct 9 16:23 .. drwxr-xr-x 9 root root 4096 Oct 9 16:25 node_modules -rw-r--r-- 1 root root 1711 Oct 9 16:25 package-lock.json root@XYZ:/app/data/modules# ls -al node_modules/ total 36 drwxr-xr-x 9 root root 4096 Oct 9 16:25 . drwxr-xr-x 3 root root 4096 Oct 9 16:25 .. drwxr-xr-x 2 root root 4096 Oct 9 16:25 .bin drwxr-xr-x 6 root root 4096 Oct 9 16:25 handlebars drwxr-xr-x 4 root root 4096 Oct 9 16:25 minimist drwxr-xr-x 2 root root 4096 Oct 9 16:25 neo-async drwxr-xr-x 4 root root 4096 Oct 9 16:25 source-map drwxr-xr-x 5 root root 4096 Oct 9 16:25 uglify-js drwxr-xr-x 4 root root 4096 Oct 9 16:25 wordwrap root@XYZ:/app/data/modules#