Created a database in mysql. When connecting in express (previously downloaded nmp mysql), compilation errors occur:

  throw err;
Error: Cannot find module 'database/database'

This is what the database.js code looks like:

const mysql= require('mysql');
module.exports= mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'root'
    database: 'testdb',

Here is index.js

const express= require('express');
const app= express();
const db= require('database/database'); //connect to db
const http= require('http');
const server= http.createServer(app);
const {Server}= require('socket.io');
const io= new Server(server);
const port= 3000;

What's wrong? Writes module not found, but I specified the correct path to database.js

Why are you sure that the path is correct? Surely it shouldn't be './database/database'?

Yaant2022-02-07 09:36:54

Really helped, but what does ./mean before the rest of the path?

Rumeone2022-02-07 09:43:11

A required module prefixed with './' is relative to the file calling require(). That is, circle.js must be in the same directory as foo.js for require('./circle') to find it. Without a leading '/', './', or '../' to indicate a file, the module must either be a core module or is loaded from a node_modules folder.

Yaant2022-02-07 09:48:03