Exemple voir code
Cors : so simple
const cors = require('cors');
app.use(cors({ origin: /http:\/\/(127(\.\d){3}|localhost)/}));
app.options('*', cors());
On remarque la regExp : http:\/\/(127(\.\d){3}|localhost)
Soit http:\/\/(127(\.\d){3} cad http://127.nb.nb.nb
ou localhost
__dirname
__dirname
n'est pas reconnu lorsque l'on passe en version de module EJS. Voici deux solutions possibles.
🪛Redéfinir __dirname
Dans test.mjs
import { dirname } from "path";
import { fileURLToPath } from "url";
import { readFile } from "fs/promises";
const path = "/hello.txt";
const __dirname = dirname(fileURLToPath(import.meta.url));
const data = await readFile(__dirname + path);
console.log(data);
console.log(data.toString());
🪛Oublier __dirname
import { URL } from "node:url";
import { readFile } from "node:fs/promises";
const path = "./hello.txt";
const data = await readFile(new URL(path, import.meta.url));
console.log(data);
console.log(data.toString());
DATE
const timestamp = new Date().getTime();
console.log(timestamp)
let DAY_FORMATTER = new Intl.DateTimeFormat(undefined, { weekday: "long",
month: "long" })
console.log(DAY_FORMATTER.format(timestamp))
DAY_FORMATTER = new Intl.DateTimeFormat(undefined, { dayPeriod: "short"
, weekday: "short", year: "numeric"
, month: "short", day: "numeric" })
console.log(DAY_FORMATTER.format(0))
Les valeurs possibles : {
weekday: 'narrow' | 'short' | 'long',
era: 'narrow' | 'short' | 'long',
year: 'numeric' | '2-digit',
month: 'numeric' | '2-digit' | 'narrow' | 'short' | 'long',
day: 'numeric' | '2-digit',
hour: 'numeric' | '2-digit',
minute: 'numeric' | '2-digit',
second: 'numeric' | '2-digit',
timeZoneName: 'short' | 'long',
// Time zone to express it in
timeZone: 'Asia/Shanghai',
// Force 12-hour or 24-hour
hour12: true | false,
}debug
le module debug est un must !
https://www.npmjs.com/package/debug
La définition des espace de noms dépendra de votre terminal :
cmd
set DEBUG=baseRange:arg,http & node app.js
git bash
Si votre terminal est git bash lancer :
DEBUG=baseRange:arg,http node app.js
PowerShell
Si votre terminal est PowerShell lancer :
$env:DEBUG='baseRange:arg,http' ; node app.js
Inscription à :
Articles (Atom)