简体   繁体   English

如何在Linux服务器上部署Node.js和MongoDB应用程序

[英]How To Deploy a Node.js and MongoDB Application on Linux server

I am developing an app and I want to deploy it on a linux server. 我正在开发一个应用程序,我想将其部署在linux服务器上。 I already have copy my local files to the server . 我已经将本地文件复制到服务器了。 I have read this article but not so clear to me https://github.com/keystonejs/keystone/issues/4687 . 我已经阅读了这篇文章,但对我来说不太清楚https://github.com/keystonejs/keystone/issues/4687

things i have already done 我已经做过的事情

Remote server has appropriate versions of Node.js & npm installed (ideally the same as what you have been testing with in development) 远程服务器已安装了适当版本的Node.js和npm(与您在开发中测试的版本完全相同)

Check out (or copy) the latest version of your application source to the remote server. 将您的应用程序源的最新版本签出(或复制)到远程服务器。

Run npm install (or npm install --production if this will be a production environment) in the top-level of your application source directory. 在应用程序源目录的顶层运行npm install(如果是生产环境,则运行npm install --production)。

but when i run npm start on the server it gives me error which is 但是当我在服务器上运行npm start时,它给我错误是

Mongoose connection "error" event fired with: { MongoError: failed to connect to server [localhost:27017] on first connect 触发了Mongoose连接“错误”事件:{MongoError:首次连接时无法连接到服务器[localhost:27017]

my settings 我的设置

keystone.init({
    'name': 'Test',
    'brand': 'Test',
    'sass': 'public',
    'static': 'public',
    'favicon': 'public/favicon.ico',
    'auto update': true,
    'views': 'templates/views',
    'view engine': '.html',
    'custom engine': cons.nunjucks,
    'mongo': 'mongodb://localhost/test',
    'auto update': true,
    'emails': 'templates/email',
    'session': true,
    'auth': true,
    'user model': 'User',
});

Do i need to configure more settings on mongo on the server? 我需要在服务器上的mongo上配置更多设置吗?

Mongoose connection "error" event fired with: { MongoError: failed to connect to server [localhost:27017] on first connect 触发了Mongoose连接“错误”事件:{MongoError:首次连接时无法连接到服务器[localhost:27017]

The above error means that your mongodb service was not started. 上面的错误意味着您的mongodb服务未启动。

To enable & start the mongodb service you can run following command: 要启用和启动mongodb服务,您可以运行以下命令:

1. Enable mongodb service 1.启用mongodb服务

sudo systemctl enable mongod.service

2. Start mongodb service 2.启动mongodb服务

sudo service mongod start

3. Start your nodejs app 3.启动您的nodejs应用

npm start

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

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