News for hackers. Stuff that matters.
Re:How I write back ends by Epskampie on Wednesday January 22, 2020 @07:13AM (#22116838)
Awesome writeup, I agree with mostly everything. A few small tips:

* Use `npm ci` instead of `npm i --no-save`. This gives you the exact packages from the lockfile, which is more reliable.

* You might like systemd .service files instead of `mon`. It's available by default on ubuntu LTS, and you're down a dependency that way. The .service files can be really simple: https://techoverflow.net/2019/03/11/simple-online-systemd-se...

Re:How I write back ends by fpereiro on Wednesday January 22, 2020 @07:24AM (#22116900)
Thanks for your comment!

- I don't use lockfiles - instead I use very very few dependencies, and I always target a specific version of each of them. I know this is not the same as a shrinkwrap, but I'm crazy enough to feel that package-lock.json adds visual bloat to my repo.

- I am biased towards mon because it's probably less susceptible to changes over time than Ubuntu itself, and because it can be installed with a single command. But systemd definitely is a good option too if you're using Ubuntu!

Re:How I write back ends by Merad on Wednesday January 22, 2020 @08:22AM (#22117287)
The main problem with your approach is that you have full control over your dependencies but no control over their dependencies, unless you're inspecting every single package in your dependency graph to make sure that every one of them targets specific versions in its package.json. Realistically, using package-lock.json and npm ci is the only way to ensure that everyone on your team and your deployments are all working off of the same node_modules folder.
Re:How I write back ends by marton78 on Wednesday January 22, 2020 @01:17PM (#22120303)
There's one problem with `npm ci`: it deletes the `node_modules` directory, thereby thwarting attempts at caching it between builds. As a workaround, we use `npm install` followed by `git diff --quiet package-lock.json`, which will abort the CI process if npm installing changed the lock file (i.e. if someone forgot to commit changes to it after adding a package).
Re:How I write back ends by riquito on Wednesday January 22, 2020 @07:34AM (#22116960)
Lockfiles protect you from someone who would publish a malware that replaces an existing version (lockfiles have hashes alongside the versions)
Re:How I write back ends by fpereiro on Wednesday January 22, 2020 @07:49AM (#22117043)
I believe that npm no longer allows for republishing existing versions. Wouldn't this restriction remove this vulnerability altogether?
Re:How I write back ends by try_again on Wednesday January 22, 2020 @07:59AM (#22117123)
It won't protect against a newer version of an established library introducing malicious behaviour.
Re:How I write back ends by bluehatbrit on Wednesday January 22, 2020 @09:57AM (#22118014)
This is correct, the few dependencies you would use would need to also target very specific versions to achieve the same.

Lock files are used to lock dependency versions all the way down your dependency tree, not just your immediate dependencies.

Re:How I write back ends by fpereiro on Wednesday January 22, 2020 @10:19AM (#22118228)
Unfortunately this seems to be the case; lockfiles would be unnecessary only if all your dependencies (and their dependencies, recursively all the way down) reference explicit versions, the risk being that a new malicious version would be published. I'll research if there's a workaround.

Thanks everyone for pointing out this issue.

Re:How I write back ends by bluehatbrit on Thursday January 23, 2020 @12:57PM (#22129891)
In my opinion a lock file really is the "work around", I don't see a huge issue in using them since it's given for free by npm and yarn with no additional overhead.
Re:How I write back ends by jessaustin on Wednesday January 22, 2020 @08:45AM (#22117461)
You can specify exact versions, but your deps might wildcard with "~" or "^" or they might specify a range of versions. Thus, a new dep of a dep might be installed the next time you update.

I wonder whether one of the npm alternatives has a "--sane" mode that would always pick the oldest possible dep...

Re:How I write back ends by t0astbread on Wednesday January 22, 2020 @09:32AM (#22117818)
Why the oldest possible?
Re:How I write back ends by jessaustin on Wednesday January 22, 2020 @10:17AM (#22118202)
Thread hypothesis is that we want to avoid breakage due to automatic dependency updates. So, don't update dependencies automatically. Now sure, if you tell the tool to update a particular dep, it will force second- and higher-order deps to update to compatible versions. It will always use the oldest compatible version, so nothing will get broken in surprising fashion. This seems strange to people who've used mostly npm and node, but tools for other languages have this policy.
Re:How I write back ends by t0astbread on Wednesday January 22, 2020 @04:37PM (#22122316)
I see. I've never heard of that before, thanks for sharing!