Chapter 4 - node.js app. Problem firing app.js via the playbook
Intertranslations opened this issue · 1 comments
In chapter 4 when deploying the app.js app and following the example as laid out in the book and the current git I couldn't get the app.js to run correctly
Adding a debug module to get the contents of forever_list I got the following error.
(Use 'node --trace-warnings ...' to show where the warning was created)
(node:36605) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency"
Running the command forever start /usr/local/opt/node/app/app.js manually in the server, I get the following error
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info: Forever processing file: /usr/local/opt/node/app/app.js
(node:19444) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:19444) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
pretty much the same error as with debugging the forever_list var.
I consulted the web about this error but couldn't find a useful solution so I added a scripts section in the package json, run manually the app.js and managed to get the web page showing in port 80.
However I would like to know the why this error occurred and how to solve it. Can anyone suggest the why or how to fix??
The content of the playbook, app and package follows below
app.js: vanilla as per git
// Simple Express web server.
// @see http://howtonode.org/getting-started-with-express
// Load the express module.
var express = require('express');
var app = express();
// Respond to requests for / with 'Hello World'.
app.get('/', function(req, res){
res.send('Hello World!');
});
// Listen on port 80 (like a true web server).
app.listen(80, () => console.log('Express server started successfully.'));
package.json
{
"name": "examplenodeapp",
"description": "Example Express Node.js app.",
"author": "Jeff Geerling <geerlingguy@mac.com>",
"dependencies": {
"express": "4.x"
},
"engine": "node >= 0.10.6",
}
playbook.yml: the part pertaining to installing npm, forever and running the app
- name: Install node.js and npm
dnf: name=npm state=present enablerepo=epel
- name: Install Forever to run the node.js app
npm: name=forever global=yes state=present
- name: Ensure node.js app folder exists
file: "path={{ node_apps_location }} state=directory"
- name: Copy example node.js app to server
copy:
src: app
dest: "{{ node_apps_location }}"
- name: Install apps dependancies as defined in package.json
npm: "path={{ node_apps_location }}/app"
- name: Check list of running node.js apps
command: /usr/local/bin/forever list
register: forever_list
changed_when: false
# - name: debug forever_list
# debug: var=forever_list
- name: Start example Node.js app.
command: "/usr/local/bin/forever start {{ node_apps_location }}/app/app.js"
when: "forever_list.stdout.find(node_apps_location + '/app/app.js') == -1"
For anyone that will come up with this problem since I had no feedback after 3 weeks.
The Accessing non-existent property 'padLevels' seems to be an incompatibility with the versions used but does not affect the run of the playbook. If you add a failed_when when getting the forever_list you may proceed with the playbook as described in the book.