error 'MODULE NOT FOUND', Cannot find module

I am trying to resole the pathing issues: this is what my files structure look like: /www/html/ /database/ databaseConnection.js /scripts/ LoginPageScript.js server.js index.html in the database js file, the following code: const mysql = require(‘mysql2’); const pool = mysql.createPool({ connectionLimit: 10, host: process.env.DB_HOST, port: process.env.DB_PORT, user: process.env.DB_USER, password: process.env.DB_PASSWORD, database: process.env.DATABASE }); pool.getConnection((err, connection) =>… Read More error 'MODULE NOT FOUND', Cannot find module

Does importing only a single function also runs other functions in that file?

I have this code in the file bmiCalculator.ts import { isNotNumber } from "./utils"; export default function calculateBmi(height: number, weight: number) { const bmi = weight / Math.pow(height / 100, 2); if (bmi < 18.5) { return "Underweight"; } else if (bmi >= 18.5 && bmi < 25) { return "Normal (healthy weight)"; } else… Read More Does importing only a single function also runs other functions in that file?

NodeJS script split into multiple files – require vs. import problems

I have 2 files: |- main.js |- lib\ |- myLib.js I added a Node.js package (camelcase in this case) to the project using NPM: "dependencies": { "camelcase": "^7.0.1" } In myLib.js I need that the camelCase function coming from this package. The myLib script defines some utility functions used in main.js. First, I tried to… Read More NodeJS script split into multiple files – require vs. import problems

ReferenceError: require is not defined (at node:internal/main/run_main_module:23:47) in Node.js

I am learning Node.js (Node.js v18.12.1) and started building my first server (backend app). here is the code const express = requrie("express"); const app = express(); const port = 3000; app.get("/", function (req, res) { res.sendFile("index.html"); }); app.listen(port, function () { console.log("Server is running on 3000"); }); However, I am getting the following error when… Read More ReferenceError: require is not defined (at node:internal/main/run_main_module:23:47) in Node.js

type 'List<dynamic>' is not a subtype of type 'Map<String, Widget>'

‘class CarouselImages extends StatefulWidget { const CarouselImages({ Key? key, }) : super(key: key); @override State<CarouselImages> createState() => _CarouselImagesState(); } class _CarouselImagesState extends State<CarouselImages> { Advertise? advertises; final AdvertiseService advertiseService = AdvertiseService(); @override void initState() { super.initState(); fetchAdsOfDay(); } fetchAdsOfDay() async { advertises = (await advertiseService.fetchAdsOfDay(context: context)); setState(() {}); } @override Widget build(BuildContext context) { return… Read More type 'List<dynamic>' is not a subtype of type 'Map<String, Widget>'

How to use a module in typescript (array syntax)?

import http from "http"; import https from "https"; const module = (options.port === 443 ? "https" : "http"); const req = [module].request(options, (res) => { console.log(res.statusCode); }); error TS2339: Property ‘request’ does not exist on type ‘string[]’. >Solution : The [module] array syntax should be changed to module. Additionally, you should use conditional importing to… Read More How to use a module in typescript (array syntax)?