Commande pour créer un serveur web rapidement
npm install -g http-server
# now use the installed command
http-server
# or
npx http-server
Légende :
-g
means--global
- une option utile est
-p
pour choisir le port du serveur- exemple :
http-server -p 80
pour un serveur web- il y a également d'autres options (voir la documentation)
Reference : http-server
npm
&& npx
npm
means "Node Packet Manager" and a lot of thingsnpx
means "Node Package eXecute", it download and execute the packageHere is some great npx
commands
npx npm-check-updates
npx unimported
npm outdated
npx -p lolcatjs -p cowsay -c 'echo hello | cowsay | lolcatjs'
// create a default value by constructing a fake similar object
const result = (playlist.tracks || { data: [] }).data;
// normal destructuring
const myObj = { hello: "world" };
const { hello: myVariable } = myObj;
console.log(myVariable); // "world"
// destructing object with key name
const keyName = "hello";
const { [keyName]: myVariable2 } = myObj;
console.log(myVariable2); // "world"
const url = "https://discord.com/api/webhooks/..."
const data = {
content: "my content",
username: "log",
avatar_url: "",
embeds: [] // for many small messages
}
fetch(url, {
method : "POST"
body: data
});
// with axios
// axios.post(url, data);
process.on('uncaughtException', (err, origin) => {
console.error('Uncaught Exception origin ->', origin);
console.error('Uncaught Exception err ->', err);
});
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled rejection promise ->', promise);
console.error('Unhandled rejection reason ->', reason);
});
# download and install
# do the post-install
nvm install node
nvm use node
# others commands
nvm list # list versions
nvm ls-remote
nvm install 'lts/NAME' # download the version
nvm alias default lts # take lts as default
const max = 16; // https://stackoverflow.com/a/32320020
const accelerate = (e) => e.playbackRate = max;
const videoAccelerate = (d) => [...d.getElementsByTagName("video")].forEach(accelerate);
videoAccelerate(document);
[...document.getElementsByTagName("iframe")].forEach((iframe)=> videoAccelerate(iframe.contentWindow.document));
function numberSafeParse(input: string): number | null {
if (input.trim() === '') return null
let parsed = Number(input)
if (!Number.isFinite(parsed)) return null
return parsed
}
// - Return `null` instead of `NaN` on failure (with matching type)
// - Doesn't parse things like "42foo" as `42` (vs using `Number.parseFloat()`)
// - Doesn't parse whitespace-only strings as `0` (vs using `Number()`)
// - Doesn't parse "NaN" into `NaN` or "Infinity" into `Infinity` (vs `Number()` or `Number.parseFloat()`)
// - In short, only parses token sequences that are *exactly* valid JS numbers
// from https://twitter.com/buildsghost/status/1766273406608294298