简体   繁体   中英

Running node.js server with mongodb error

I'm still new to node.js and mongodb. Now I'm trying to solve this problem.

I have instructions to run my server without any problems, I follow them and yes my server works. But when I switched the server off then run it again I face this bug:

[vagrant@localhost ~]$ node /opt/inapsrv/app/app.js 
app-api listening at http://0.0.0.0:7000

/opt/inapsrv/node_modules/fileupload/lib/modules/file.js:23
  throw error
        ^
Error: ENOENT, mkdir 'data/imagex/'

And here is the line of the directory above taken from app.js file:

var imagePath = 'data/imagex/';

I tried to:

  • make vagrant and mongo users as super users and they have the root permissions.
  • to run "sudo node /opt/inapsrv/app/app.js"
  • run "forever /opt/inapsrv/app/app.js"

and it didn't work.

I don't know why it successfully ran the first time, and then it didn't! Any help?

I suspect you're using node module fileupload for the upload job. The source code fragment in fileupload that throws your error can be found here .

The problem with the code used in fileupload module is that it does not create recursive directories since fs.mkdir is used. To fix your issue try to create the upload directory or at least data upfront. You could do this by a npm script, in app.js using the mkdirp or simply by a shell script.

The problem described is not related to mongodb or mongoose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM