Js project var a = require ('.. / hello'); require is not defined is reported if you write like this

jsnode;index.jsrequire()require is not defined

Dec.20,2021

  1. the next time you post the code, try not to post screenshots. Many people answer questions on mobile phones, and the eyes that look at the code are terrible, not to mention that sometimes they have to copy the code to answer the questions.
  2. see that there is a layui, in the code and the file is in the public folder, indicating that it is a static resource, that is, the js, running in the browser environment, which does not have require by default, unless you refer to the library manually. That's why you reported it wrong.
  3. look at this thing called db, that you are going to quote, guess it should be something of the ActiveRecord class? I don't know how the logic is written, but try to follow the MVC model. If you need to mix the front and back end, you can use a template engine, such as Pug or ejs, but do not put it directly into the public, this folder is directly visible in the front end, do not expose the things in the back end directly.

your index.js file is your static resource and runs in the browser. The browser naturally does not support require


Please post the code in your require ()

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e630cb-444d6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e630cb-444d6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?