I
I
Ivan Smirnov2018-12-09 18:11:22
Node.js
Ivan Smirnov, 2018-12-09 18:11:22

How to use require in nodejs like require in PHP?

I need the require function to work like in PHP

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Decadal, 2018-12-09
@Decadal

take php

O
olezhenka, 2018-12-09
@olezhenka

So that the code is simply "copied" as in PHP and another file can see and use the variables of the current file? No way.
In a node, files are modules in which there are no other environments than their own.

V
Vitaly, 2018-12-09
@vshvydky

the request function in the node works as it should. if you came to a node with php, you can safely turn around and go back, because a good code may not work out.

M
Maksim B, 2018-12-09
@Sundagy

function php_require(module){
    delete require.cache[require.resolve(module)]
    return require(module)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question