Problems with "Build Your First Node App"

This book started off OK - the initial exercise went fine. But as soon as it got into installing hapi it all went downhill.

npm install --save hapi hoek

Installed OK but after telling me it was a deprecated version.

Subsequently trying to run the server.js results in:

internal/modules/cjs/loader.js:596
throw err;
^

Error: Cannot find module ‘dotenv’
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (/Users/jonparis/NodePlay/settings.js:3:3)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)

I haven’t created a dotenv - have no idea what it is and no idea where to look.

This is supposed to be a beginners book on node - am I being unreasonable to expect the scripts to work?

Follow up. I found from this article https://www.sitepoint.com/node-js-mvc-application/ (which contains much of the same material) that the book seemed to have omitted the step to:
npm install -s dotenv

I ran this and dotenv installed but still an error. I now get:

JonsMacBook:nodeplay jonparis$ node server.js
/Users/jonparis/NodePlay/server.js:9
server.connection({ port: Settings.port });
^

TypeError: server.connection is not a function
at Object. (/Users/jonparis/NodePlay/server.js:9:10)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
at startup (internal/bootstrap/node.js:238:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)

Hi Jon,

Thanks for the feedback. I can confirm the book does have the info on installing dotenv if you are wanting to use it. This is included in the tip section: Using a .env File.

In relation to the next error yes you are correct it looks like we have some issues. This is because of the version of hapi has since been updated from when the book was published and the API has changed so this is not going to work without using the same version we used in the book.

I will forward this to our book team to look into what we will do with this book as it would need updates made to account for the version changes.

I apologize for the issues you have had with this and will let you know the team respond with.

Thank you.

1 Like

Hi,

Sorry for the late response, I was on vacation.

I just had a look at the book you are having problems with (it’s this one, right?) and as @mrlagmer says, the code is outdated.

I was a little surprised to find that this is the case, as this book also went out as an email course last year (Sept 2018) and the code was brought up to date (by me) for the occasion.

I’ve passed this on to HQ and am told that the book will be updated in the next week or so. In the meantime, here’s a repo that I created for the original update: https://github.com/jameshibbard/notes-board

Sorry for the inconvenience and hope this helps some.


BTW, I see that on p3 of the book it says “This project was tested on Node v6.” - that should be a bit of a red flag. Node is currently on v12, so you can pretty much guarantee that something written for Node v6 will have issues if you try to run it today.

I know this is a PITA, but the JavaScript landscape is somewhat notorious for moving quickly (just try googling “JavaScript fatigue”), so it always pays to give tutorials a quick once over to make sure they are reasonably up-to-date, before investing too much time in following them.

2 Likes