Require is undefined in javascript
MikeJMS8910

I am trying to set up express and I downloaded node.js, npm, and all of the things that I would need for it. But when I do const express = require('express') I get the error request is undefined. I have been searching the internet for the past 3 hours but nothing works and I keep getting the same error. How can I fix this?

You are viewing a single comment. View All
Answered by Coder100 [earned 5 cycles]
View Answer
Coder100

Did you do it in nodejs or HTML?
Require only works in node.js silly

Coder100

so like hit win + r, type in cmd.exe, press enter and then cd to your project folder and do node . @MikeJMS8910

MikeJMS8910

@Coder100 yea I did do node.js. I had someone else test it for me and they said that it works for them so I think the problem is from which version of node I have installed on my computer(I am scripting this in vs code not repl.it)

Coder100

@MikeJMS8910 send error and code

MikeJMS8910
Coder100

You set in package.json that the main file is app.js, but you made app.js instead. @MikeJMS8910

MikeJMS8910

@Coder100 I dont really understand, but then what do I need to do in the package.json

Coder100

change "main": "index.json" to "main": "app.json" also you still have to sent screenshot of the error. @MikeJMS8910

MikeJMS8910

@Coder100 app.json or app.js?

MikeJMS8910

@Coder100 and here is the error

Coder100

oh i see
you have to actually run it with node node app.js @MikeJMS8910

MikeJMS8910

@Coder100 ok I know what I was doing wrong now. I wasnt running the script like you said and then I was going to the file directory instead of localhost:3000

Coder100