V
V
vizaville2015-04-14 22:41:48
Node.js
vizaville, 2015-04-14 22:41:48

Path to node.js module?

I am writing in webstorme for node. wrote the database module. I connect it var DataBase = require('database.js');Everything is fine, I upload it to VDS and it does not find it, but finds it if I write var DataBase = require('./database.js');
How to fix it so that it is the same on the local and remote server?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Shemsedinov, 2015-04-14
@vizavill

If the module is located in node_modules, then it will normally be loaded through the name: require('database'), and you most likely made not a module, but a separate file that can be loaded not through the name, but through the path, require('/path/ database.js') or via require('./database.js') from the current folder. On some systems it also finds require('database.js') or require('./database') or require('/path/database.js'), but it's better to write require('./database.js') or do full-fledged modules in node_midules, which will have its root file specified in its package.json in the "main" parameter and then it can be loaded by name from anywhere in the code (any directory and any js file in the project).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question