Can't load Require in Nodejs

I’ve written the same code in vs Code but it’s not working…

const express = require(‘express’)

const app = express()

app.get(’/’, (req, res) => {
console.log(req.url)
res.send(‘Hello There!’)
})

app.listen(3333)

This is the code. It must show “Hello There!”

Error :- Uncaught ReferenceError: require is not defined

Please help soon

Are you able to console log req.url?

@shivam.bhatia123

nothing printing on the web page.

console is printing this error msg

Error :- Uncaught ReferenceError: require is not defined

I’m stuck here for 2 days. please help

Can you send me this project’s github link?

@shivam.bhatia123 there is no file on the github for this small piece of code. It’s just a JS file

–>
const express = require(‘express’)

const app = express()

app.get(’/’, (req, res) => {
console.log(req.url)
res.send(‘Hello There!’)
})

app.listen(3333)
<–
I just typed this after doing
npm init
npm install express

it must print “Hello There!” (as it worked for the mentor in the video)

but it didn’t

Write this and it will work:
const express = require(‘express’);

const app = express()

app.get(’/’, function (req, res) {

console.log(req.url)

res.send(‘Hello There!’);

})

app.listen(3333)

@shivam.bhatia123
@shivam.bhatia123

Still not working… what’s the issue here.?

doubt1Browser

@shivam.bhatia123

It’s not working…???

Are you running node script.js?

@shivam.bhatia123
Yes, if I do open it in the VS code terminal and write “node app.js”

it gives syntax error in the first line

SyntaxError: Invalid or unexpected token

Yiu should share this code on github then only I can see what files you are missing because code seems to be correct

@shivam.bhatia123

Click here for the repository Github

I’ve uploaded all the files, hope you find the mistake and clear my doubt

Node_modules are not present and don’t use `(back tick) in this use ’ (inverted comma)

@shivam.bhatia123

  1. I’ve installed node modules but couldn’t upload it due to some error.
  2. where I’ve to update the backticks (please specify line numbers)

Everywhere it is not needed in this file change them to ’ (inverted comma)