Lädt...

🔧 TIL: Synchronous import in ES-Modules using module.createRequire (Node)


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

I've been looking for a way to inject a configuration file like process.cwd()+"/my-config.js" into a configuration file in a node package I work on. The problem with dynamic import(process.cwd()+"/my-config.js") is, that is async. But the underlying tools need my config file to be sync.

Searching for "node synchronous dynamic import" I found the answer on stackoverflow: "Convert import() to synchronous".

There is a functionality in Node for that: module.createRequire(filename) (see the docs)

// node_modules/my-package/config.js

import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);

const userConfig = require(`${process.cwd()}/my-config.js`);

export const config = {
    property1: "fallback-value",

    ...userConfig.config,
}; 

Editing-Notes: 1. IRL I'd use path.join(process.cwd(), "my-config.js"). 2. I was not able to nest \` in order to show inline code for template strings.

...

🔧 Execution of Synchronous and Asynchronous Functions in Node.js


📈 28.02 Punkte
🔧 Programmierung

🔧 Alias your module directory with Node standard import mapping


📈 25.21 Punkte
🔧 Programmierung

🔧 AWS SnapStart - Part 22 Measuring cold and warm starts with Java 17 using synchronous HTTP clients


📈 25.13 Punkte
🔧 Programmierung

⚠️ #0daytoday #WebKit - UXSS Using JavaScript: URI and Synchronous Page Loads Exploit [#0day #Exploit]


📈 25.13 Punkte
⚠️ PoC

⚠️ [dos] WebKit - UXSS Using JavaScript: URI and Synchronous Page Loads


📈 25.13 Punkte
⚠️ PoC

🔧 TIL: How Node's event loop actually works.


📈 22.6 Punkte
🔧 Programmierung

🕵️ Huawei NGFW Module/IPS Module SIP Module SIP Message denial of service


📈 22.26 Punkte
🕵️ Sicherheitslücken

🕵️ Huawei NGFW Module/IPS Module SIP Module SIP Message denial of service


📈 22.26 Punkte
🕵️ Sicherheitslücken

🕵️ Huawei NGFW Module/IPS Module COPS Module Message memory corruption


📈 22.26 Punkte
🕵️ Sicherheitslücken

🕵️ Huawei NGFW Module/IPS Module SIP Module SIP Message denial of service


📈 22.26 Punkte
🕵️ Sicherheitslücken

🕵️ Huawei NGFW Module/IPS Module SIP Module SIP Message Denial of Service


📈 22.26 Punkte
🕵️ Sicherheitslücken

🕵️ Huawei NGFW Module/IPS Module COPS Module Message Pufferüberlauf


📈 22.26 Punkte
🕵️ Sicherheitslücken

🔧 Error: Can't find stylesheet to import. 75 @import '@angular/material/theming';


📈 21.61 Punkte
🔧 Programmierung

🕵️ Import users from CSV with meta <= 1.12 - Import Cross-Site Scripting (XSS)


📈 21.61 Punkte
🕵️ Sicherheitslücken

🕵️ PlaySMS 1.4 Phonebook Import import.php HTTP Header erweiterte Rechte


📈 21.61 Punkte
🕵️ Sicherheitslücken

🕵️ Low CVE-2022-2146: Import csv files project Import csv files


📈 21.61 Punkte
🕵️ Sicherheitslücken

🕵️ College Publisher Import Plugin up to 0.1 on WordPress CSV File Import unrestricted upload


📈 21.61 Punkte
🕵️ Sicherheitslücken