The error message in Express points to module.js line 550 and states that the module cannot be

I am currently in the process of setting up a basic express application using the code below:

const express = require('express');
const app = express()
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const mongoose = require('mongoose');
port = 3000


//creating the db
mongoose.connect('mongodb://localhost:27017/Criptare',{ useNewUrlParser: true,
useCreateIndex: true });
let db = mongoose.connection
db.on('error',console.error.bind(console,"connection error"));

//parsers 
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));

//session LATER


//static files
app.use('/static',express.static('public'));

//view engine PUG
app.use('view-engine','pug');

//Routes
const mainRoutes = require('./routes/main')
app.use(mainRoutes)

//error handle
app.use((req,res,next)=>{
    let err = new Error('Looks like the page you were looking for was not found')
    err.status = 404;
    next(err)
})
app.use((err,req,res,next)=>{
    res.locals.error = err
    res.status(err.status);
    res.render('error')
});
app.listen(port,()=>{
    console.log(`No bun serveru ii on pe ip-ul:localhost:${port}`)
})

When I run it with nodemon, I encounter the following error:

module.js:550
throw err;
^
Cannot find module 'C:\Proiecte code\ON\express\criptare\index.js'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3

Does anyone have any insights into why this error is occurring? All dependencies are listed in the package.json file.

Answer №1

To execute your filename.js file, navigate to its directory and type in the command node filename.js

Initialize npm in the current directory where your script is saved.

Answer №2

I encountered the identical problem, but it was resolved by executing the command "yarn"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Combining php with jquery

This message contains a successful integration of PHP code within jQuery using the AJAX method. However, there are errors encountered which may be due to my lack of experience in jQuery. Uncaught ReferenceError: save_customer is not defined Uncaught Synt ...

Properly specifying the data type for a generic type variable within a function in TypeScript

As I work on my express project, I am currently coding a function called route. const morph = (params: Function[]) => (req: Request) => params.map(f => f(req)) const applyTransformers = (transformers: Function[]) => (response: any) => { ...

When changing the dropdown option on a separate page in React/Next JS, all checkboxes show the clicked style as a result of utilizing useState

I have implemented checkboxes for three different categories: "Types", "Price", and "Categories". They function correctly, with data being passed to a separate checkbox component without any issues. The problem arises when I click a checkbox and then inte ...

Find the location of the .env file directory in Create-React-App outside the root directory

After setting up a new web application using create-react-app (CRA), I find myself in need of incorporating environment files to configure different endpoints. While CRA comes equipped with the handy dotenv package, there is a slight hiccup - I prefer to h ...

Is there a way to properly structure the json data displayed in my network tab on Chrome?

After sending an http request to my backend, I received a json response in the network tab. However, the format of the json is unreadable. To clarify, here is a screenshot: https://i.stack.imgur.com/RBiTd.png Currently using Chrome, I am seeking assistanc ...

Removing all comments from a post that has been deleted in MongoDB

I am currently following the MEAN stack tutorial provided by Thinkster () and I have encountered an issue with implementing delete operations. Here are the schemas I am working with: var PostSchema = new mongoose.Schema({ title: {type: String, required ...

The issue with GatsbyJS and Contentful: encountering undefined data

Within the layout folder of my project, I have a Header component that includes a query to fetch some data. However, when I attempt to log this.props.data in the console, all I get is 'undefined'. Could someone please point out where I might be m ...

Node validation middleware: Ensuring data integrity

Within my node application, there exists a specific express route that looks as follows. router.post('/register', asyncMiddleware(async (req, res) => { const { error } = validateUser(req.body); if (error) return res.status(400). ...

Transform ajax functionality into jquery

I need help converting an AJAX function to a jQuery function, but I'm not sure how to do it. function convertToJquery() { // Create our XMLHttpRequest object var hr = new XMLHttpRequest(); // Set up variables needed to send to PHP file var ur ...

What is the best way to send parameters from an Express route to a Node middleware?

After searching through the documentation without success, I am seeking help to achieve my goal. Here are some of my express routes: app.post( '/submit-agency-event' , eventService.submitEvent ); app.post( '/submit-question' ...

Overlapping Divs - HTML Elements Crossing Paths

My challenge is to position the Social Icons at the bottom of the screen and align the Image Gallery in the middle. However, the social Icons keep moving to the center of the screen and the Image gallery ends up overlapping them, making it difficult for me ...

NPM build is functioning properly, however NPM start is not working as expected for the create-react-app project

After using create-react-app, I noticed that when I first run 'npm start' everything works perfectly. However, if I cancel the process, localhost starts returning a 404 error. Here's what my terminal is showing: Compiled with warnings. ./ ...

Encountering the error message "Preset 'react-server' not located in the specified directory..."

Error message in full: ../assets/around/TCircle.svg Module build failed: Error: Couldn't find preset "react-server" relative to directory "/Users/admin/Documents" at Array.map (native) The error mentioned keeps popping up, yet there is no ...

What is the process for verifying a checkbox after it has been selected?

I simplified my code to make it easier to understand const [factor, setfactor] = useState(1); const [nullify, setNullify] = useState(1); const Price = 10; const Bonus = 15; const finalPrice = (Price * factor - Bonus) * nullify; // start ...

Navigating the issue of updateMany not functioning properly in mongoose and nodejs

I need assistance with updating the author name of a post whenever the user updates their profile name. My code is as follows: router('/:id', async (req, res) { if (req.body._id == req.params.id) { try { const user = await ...

Encountering an error: Reading an undefined property - NodeJS, Express, and Mongoose

These are the two functions I have: exports.list = function (req, res){ Material.find(function(err, materials) { res.render('materials/list', {title: 'Pagina Materiali', materials: materials}); }); } exports.modify = function (req ...

The quickest regular expression match possible if it is already a subsection of another match

Is there a simple way to find the shortest match in a long text where strings are repeated? I'm having trouble because matches within already matched text aren't being found. Here's an example of the issue: Using code: "ababc".match(/a.+c ...

New feature incorporated at the end of choices in MUI auto-suggest widget

Currently, I'm working on enhancing a category adder feature. Previously, I had limited the display of the "add category chip" to only appear for the no-options render scenario. However, I came across an issue where if there was a category like "softw ...

What could be causing Laravel Sail NPM to display the error message 'unsupported version of Node.js'?

In the midst of a Laravel 8 project using Docker, I find myself knee-deep in SCSS design. However, a hurdle arises when attempting to compile my SCSS files. NPM insists that my Node version is outdated at 12.x, even though within my container I am actually ...

Is it possible to adjust the width of a parent element based on the number of child

In this particular example, I have structured a header with a logo-container positioned on the left side, a menu in the center, and a button on the right. The menu consists of 5 top-level items and 2 sub-menus. <div class="container"> <div cla ...