Javascript, Node Brain
clean NPM cache
When you have just released a new package version and npm install in another project says the package doesn’t exist, that could be because it tried to fetch the package before it was really live on npmjs.org. The problem is that it then remembers this forever. So you need to clear out the cache with
npm cache clean --force
Run npm script in a different dir with
shellnpm --prefix <path> run <command>
npx
npx lets you create a command line tool that can be run without already having it installed. To turn your npm module into such a command give it
should have a javascript file with a shebang line like this: #!/usr/bin/env node. This can be in your Typescript file and the compiler should
make sure it ends up in the final output js file.
Then in your package.json file needs a bin entry pointing to the script like this:
{
"bin": {
"amx": "build/cli.js"
}
}
Now publish your module and run it from another shell with npx -g modulename
Temporal
Temporal is a new Javascript Date & Time API that is easier to use and provides features the old Date api does not.
Dom
Get callbacks when the browser goes on or offline:
javascriptconst hand_online = () => {
console.log('we are online')
}
const hand_offline = () => {
console.log('we are offline')
}
window.addEventListener("online", hand_online)
window.addEventListener("offline", hand_offline)
As a React book: