Solve Error Uncaught ReferenceError: require is not defined in Node.js Pratik Sah The Crazy Programmer
While working with Node JS, you might be familiar with the require() and sometimes, it shows error like Uncaught ReferenceError: require is not defined. So why does this happens? Let’s see in today’s post. Before coming to the error, let’s know what is require() used for. What is require? The require function is the builtin function of node js that helps us to include local or node_modules in our project that exists in a separate file. const express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => res.send('Hello World!')) app.listen(port, () => console.log('App is running!')) Here, we have imported express module into our code using require('express') . The require function will look for files in builtin core modules, NPM modules(node_modules), local modules, etc. Now, let’s see what is the reason for the error. Here is an example code. let http = require('http'); http.createServe