How To Deploy a Node.js and MongoDB Application on Linux server - javascript

I am developing an app and I want to deploy it on a linux server. 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.
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)
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.
but when i run npm start on the server it gives me error which is
Mongoose connection "error" event fired with:
{ MongoError: failed to connect to server [localhost:27017] on first connect
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?

Mongoose connection "error" event fired with: { MongoError: failed to connect to server [localhost:27017] on first connect
The above error means that your mongodb service was not started.
To enable & start the mongodb service you can run following command:
1. Enable mongodb service
sudo systemctl enable mongod.service
2. Start mongodb service
sudo service mongod start
3. Start your nodejs app
npm start

Related

How to deploy my own backend with AWS amplify

I'm pretty new to AWS Amplify and I'm trying to deploy an app with my own frontend and backend, I have successfully deployed the frontend but I can't figure out how to connect the backend (it seems like the server is not responding).
Here's my project structure:
And Here's my amplify.yml
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
# IMPORTANT - Please verify your build commands
build:
commands: []
artifacts:
# IMPORTANT - Please verify your build output directory
baseDirectory: 'client'
files:
- '**/*'
cache:
paths:
- node_modules/**/*
I got a warning on the website:
Failed to load resource: the server responded with a status of 404 ()
I also tried adding the code below to the yml
version: 1
env:
variables:
key: value
backend:
phases:
build:
commands:
- amplifyPush --simple
But the application failed when building
Not sure if this has something to do with using express.js in node.js

mup deploy error - x Start Meteor: FAILED

On Windows 10 PowerShell as admin, trying to deploy a Meteor app using mup, onto a VPS Ubuntu 20.04.2 LTS, all went good but failed to start meteor, as show in the bottom of the print out. I "think" that it is because this sentence at the end;
Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use.
Server reports:
root#server:~# netstat -tulpn | grep --color :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 231/apache2
Any idea how to fix this issue where I need Apache to be running as well as nodeJs? Thank you
Update:
The following is the output of mup deploy --verbose, followed by the file mup.js
C:\my-app-dir\.deploy>mup deploy --verbose
Active Connections
Proto Local Address Foreign Address State
TCP 127.0.0.1:49675 LAPTOP-OLT811G5:49676 ESTABLISHED
TCP 127.0.0.1:49676 LAPTOP-OLT811G5:49675 ESTABLISHED
TCP 127.0.0.1:50151 LAPTOP-OLT811G5:50152 ESTABLISHED
TCP 127.0.0.1:50152 LAPTOP-OLT811G5:50151 ESTABLISHED
TCP 127.0.0.1:50154 LAPTOP-OLT811G5:50155 ESTABLISHED
TCP 127.0.0.1:50155 LAPTOP-OLT811G5:50154 ESTABLISHED
TCP 127.0.0.1:50160 LAPTOP-OLT811G5:50161 ESTABLISHED
TCP 127.0.0.1:50161 LAPTOP-OLT811G5:50160 ESTABLISHED
TCP 127.0.0.1:52367 LAPTOP-OLT811G5:52368 ESTABLISHED
[185.148.129.235] - Pushing Meteor App Bundle to the Server: SUCCESS
[185.148.129.235] - Prepare BundlePTOP-OLT811G5:52800 ESTABLISHED
Updating base image52800 LAPTOP-OLT811G5:52799 ESTABLISHED
node-12-base: Pulling from abernix/meteord811G5:55366 ESTABLISHED
Digest: sha256:79c9c29c028fd72320fa1af5e2bab1147db3c206a9d807e9bdb3fb2110660c1a
Status: Image is up to date for abernix/meteord:node-12-baseLISHED
docker.io/abernix/meteord:node-12-base-OLT811G5:60241 ESTABLISHED
Preparing for docker build LAPTOP-OLT811G5:64587 ESTABLISHED
Creating Dockerfile64587 LAPTOP-OLT811G5:64586 ESTABLISHED
Finished creating Dockerfile LAPTOP-OLT811G5:65122 ESTABLISHED
Building image.0.1:65122 LAPTOP-OLT811G5:65121 ESTABLISHED
Sending build context to Docker daemon 128.6MB:65151 ESTABLISHED
Step 1/7 : FROM abernix/meteord:node-12-base1G5:65150 ESTABLISHED
# Executing 1 build trigger 40.119.211.203:https ESTABLISHED
---> Using cache0.67:52400 142.250.4.188:5228 ESTABLISHED
---> 65200bf0c802.67:52422 40.119.211.203:https ESTABLISHED
Step 2/7 : RUN mkdir /built_app || true216-3-76:https ESTABLISHED
---> Using cache0.67:52447 syd15s17-in-f3:https ESTABLISHED
---> 641135f006a7.67:52449 syd09s14-in-f14:https ESTABLISHED
Step 3/7 : ARG ROOT_URL="http://185.148.129.235.static.a2webhosting.com"
---> Using cache0.67:52625 151.101.193.69:https ESTABLISHED
---> 51449bdf1771Documents\meteor\apps\audio\.deploy> mup deploy --verbose
Step 4/7 : ARG MONGO_URL="mongodb://mongodb:27017/audio"
---> Using cache
---> 9e90ec530e62Pushing Meteor App
Step 5/7 : ARG MONGO_OPLOG_URL="mongodb://mongodb/local"ver
---> Using cache
---> be34137de50b
Step 6/7 : COPY ./ /built_app
---> Using cache
---> c23d46e03e72
Step 7/7 : RUN cd /built_app/programs/server && npm install --unsafe-perm
---> Using cache
---> fccd4584401f
[Warning] One or more build-args [NODE_VERSION] were not consumed
Successfully built fccd4584401f
Successfully tagged mup-audio:build
real 0m9.804s
user 0m0.769s
sys 0m1.010s
Tagged latest
Deleted Images:
deleted: sha256:e869f38ad6f15504fdacb6c286dd7904521f4bf2eb00f699fdefb4fa4d4857e1
deleted: sha256:538b72c0548dcc8e1def78d335a34e448d611ed55105cfcd132f1dc7bfe12ac7
deleted: sha256:16b87889c911fdaeb4225509b676468f9c7df9208fd3e17c075c08646b840c51
deleted: sha256:f2b507302cb528f88d72a8837d74b1d523f60426b0dda43fcb0369f9bf1eef27
Total reclaimed space: 139.4MB
[185.148.129.235] - Prepare Bundle: SUCCESS
Started TaskList: Configuring App
[185.148.129.235] - Pushing the Startup Script
[185.148.129.235] - Pushing the Startup Script: SUCCESS
[185.148.129.235] - Sending Environment Variables
[185.148.129.235] - Sending Environment Variables: SUCCESS
Started TaskList: Start Meteor
[185.148.129.235] - Start Meteor
using image
removing last
Image mup-audio:latest
Volume
Removing docker containers. Errors about nonexistent endpoints and containers are normal.
audio
Error response from daemon: endpoint audio not found
Error: No such container: audio-frontend
Error response from daemon: endpoint audio-frontend not found
Error: No such container: audio-nginx-letsencrypt
Error response from daemon: endpoint audio-nginx-letsencrypt not found
Error: No such container: audio-nginx-proxy
Error response from daemon: endpoint audio-nginx-proxy not found
Finished removing docker containers
e63e684acf2ba89117a8ee7c4a53c28ca08cd5fdeacc8c7b368689fcd36172b1
docker: Error response from daemon: driver failed programming external connectivity on endpoint audio (6dcafd574d2116c25d289cc71e15c41112b53a049a52c6481ecd20e51ec8414c): Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use.
[185.148.129.235] x Start Meteor: FAILED
------------------------------------STDERR------------------------------------
Removing docker containers. Errors about nonexistent endpoints and containers are normal.
Error response from daemon: endpoint audio not found
Error: No such container: audio-frontend
Error response from daemon: endpoint audio-frontend not found
Error: No such container: audio-nginx-letsencrypt
Error response from daemon: endpoint audio-nginx-letsencrypt not found
Error: No such container: audio-nginx-proxy
Error response from daemon: endpoint audio-nginx-proxy not found
Finished removing docker containers
docker: Error response from daemon: driver failed programming external connectivity on endpoint audio (6dcafd574d2116c25d289cc71e15c41112b53a049a52c6481ecd20e51ec8414c): Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use.
------------------------------------STDOUT------------------------------------
using image
removing last
Image mup-audio:latest
Volume
audio
e63e684acf2ba89117a8ee7c4a53c28ca08cd5fdeacc8c7b368689fcd36172b1
------------------------------------------------------------------------------
******************************************************************************
//mup.js
module.exports = {
servers: {
one: {
host: '185.148.129.235',
username: 'root',
password: 'abcdefghij',
opts: {
port: 7822
}
}
},
app: {
name: 'audio',
path: '../',
servers: {
one: {},
},
buildOptions: {
serverOnly: true,
},
env: {
ROOT_URL: 'http://185.148.129.235.static.a2webhosting.com',
MONGO_URL: 'mongodb://mongodb/meteor',
MONGO_OPLOG_URL: 'mongodb://mongodb/local',
},
docker: {
image: 'abernix/meteord:node-12-base',
},
enableUploadProgressBar: true
},
mongo: {
version: '3.4.1',
servers: {
one: {}
}
},
};
Since the Ubuntu VPS had Apache2 server listening on port 80, and mup makes the same port number for the docker-containing-meteor-app to listen on. I needed to stop the Apache2 systemctl stop apache2, then mup deploy worked and now the meteor app is accessable on the browser.
Now I need to find out how to use nginx as a proxy for the meteor app.

How to run openshift MEAN project in localhost or development system Ubuntu?

I have created a MEAN stack application on https://openshift.redhat.com/ and it was successfully running on the web.
Default source code of the project synced form: https://github.com/linnovate/mean-on-openshift.git
For further development I am cloning the hosted git source using using git url mentioned in the applications page. (e.g git clone ssh://55e86e9f89f5cf1d29000001#nodejs-tapslab.rhcloud.com/~/git/nodejs.git/).
After clone the source code to local system, opening the project in sublime text editor. I can see in the config/env/development.js there are lot of configuration are used like process.env.OPENSHIFT_XXX. I was changed the some config value mentioned below and trying to start server using command : 'node server', but server was not starting throwing error.
{
db: db: 'mongodb://' + (process.env.DB_PORT_27017_TCP_ADDR || 'localhost:27017') + ':' + '/mean-dev',
hostname: process.env.OPENSHIFT_NODEJS_IP || 'http://localhost:3000'
}
Can someone help me how to run Openshift mean project in local system and what all configuration needed before running it in local system.
System Config :
Ubuntu 12.04
MongoDB v2.6.6
Nodejs v0.10.40
npm 1.4.28
grunt-cli v0.1.13
Error :
$ node server
Mean app started on port 3000 (development)
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
Git:
$ NODE_ENV=test node server

Mongodb Not connecting in Node js

In Node js using mongodb for saving user chat and users. All the work is done on local. Mongodb work properly but today not connected and return following error.
{ [MongoError: connect ECONNREFUSED] name: 'MongoError', message: 'connect ECONNREFUSED'
and my code is
Sounds like mongod server isn't running. The mongod command won't work if your MongoDB installation doesn't have rights outside the core mongo directory. This is common on Windows installations, especially.
Try changing your working directory in your terminal to your Mongo installation directory. On a Windows machine, e.g. cd C:\Program Files\Mongo then run mongod --dbpath (yourAppDBdirectory).

GruntFile automated deployment using ssh (Windows)

I am trying to set up a GruntFile.js file to automate the process of logging on to my personal website's server via ssh and pulling the latest version of the git repo. The relevant part of my grunt file looks like this:
sshconfig: {
portfolioServer: {
host: 'mySite.com',
username: 'root',
agent: process.env.SSH_AUTH_SOCK,
}
},
sshexec:{
deploy:{
command: [
'cd portfolio',
'git pull'
].join(' && ')
},
options:{
config: 'portfolioServer'
}
},
However, when I run the associated task (I named it "grunt deploy"). I get the following error.
Running "sshexec:deploy" (sshexec) task
Warning: Connection :: error :: Error: Authentication failure. Available authentication methods: publickey,password Use --force to continue.
Aborted due to warnings.
My understanding is that this error means that I have not set up the public/private ssh keys correctly. However, I have already gone through the process of setting up public/private keys.I am already able to run the following command through git bash and log in successfully:
ssh root#mySite.com
I have searched online for this problem and it seems like it might have something to do with process.env.SSH_AUTH_SOCK not behaving in git bash on windows in the same way that it might be expected to be have in a native linux distribution.
What further steps in my setup do I have to take in order to make this deployment configuration work?

Categories

Resources