简体   繁体   English

使用mongodb错误运行node.js服务器

[英]Running node.js server with mongodb error

I'm still new to node.js and mongodb. 我对node.js和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: 这是上面来自app.js文件的目录行:

var imagePath = 'data/imagex/';

I tried to: 我试过了:

  • make vagrant and mongo users as super users and they have the root permissions. 使无业游民和mongo用户成为超级用户,他们具有root权限。
  • to run "sudo node /opt/inapsrv/app/app.js" 运行“ sudo节点/opt/inapsrv/app/app.js”
  • run "forever /opt/inapsrv/app/app.js" 运行“永远/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. 我怀疑您正在使用节点模块fileupload进行上载作业。 The source code fragment in fileupload that throws your error can be found here . 可以在此处找到fileupload中引发错误的源代码片段。

The problem with the code used in fileupload module is that it does not create recursive directories since fs.mkdir is used. fileupload模块中使用的代码的问题在于,由于使用了fs.mkdir ,因此不会创建递归目录。 To fix your issue try to create the upload directory or at least data upfront. 要解决您的问题,请尝试创建上传目录或至少创建data You could do this by a npm script, in app.js using the mkdirp or simply by a shell script. 您可以通过使用mkdirp在app.js中使用npm脚本或仅通过Shell脚本来执行此操作。

The problem described is not related to mongodb or mongoose. 描述的问题与mongodb或mongoose无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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