React: How to publish page on server using React-starter-kit - node.js

So, I created a page using repo from:
https://github.com/kriasoft/react-starter-kit
I have my own global ftp server. And now I would like to publish my project on server.
What is the best way to do it. Should I copy all files to ftp server and just exec command 'npm start'? Or maybe I should deploy it?
I'm new in web deployment and not sure how it works.
Thanks for any tips.

It may be a little more complicated than just ftping your project up. Here are the instructions I use to setup a server at digitalocean.
sudo apt-get update
sudo apt-get install npm
sudo apt-get install git
sudo apt-get install ufw
sudo apt-get install build-essential libssl-dev
curl https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash
nvm install stable //may require new ssh session before this
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw allow 80/tcp
ufw allow out to any port 53
ufw enable
sudo npm install -g forever
sudo npm install -g node-gyp
cd /var
mkdir www
cd www
git clone https://github.com/calitek/palminfo --recursive
npm install
npm ls -depth 0
export PORT=80
node js/server.js
test using ip / when good exit then
forever start js/server.js
set dns
The server will need to support you adding node.js. Then you need to preferably use github to clone the project. You will want to do the npm install on the server to be sure you are using the correct modules. Its a little complicated the first time out, just keep good notes for the next time.

This is a big topic to cover, whatever your linux distribution is, you probably will always need 2 servers - a proxy server, and an app server.
I'd recommend you wrap your compiled sites with a simple Node.js server like Express or Hapi. Then configure nginx to properly route all the requests to the application. Checkout some detailed guides from DigitalOcean
CentOS: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-centos-7
Ubuntu: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04
Minor steps might be slightly different but you get the idea

One approach is to build the app on the server, but you will need something like Heroku which you already decided to go with.
But an alternative to that is to do a paradigm shift. You're app is basicaly just some html, css and javascript, which is compiled and servered to the public. You could compile that yourself with npm run build and then just copy the compiled files to your hosting server which can use what ever server it wants: apache httpd, nginx, etc. This is also cheaper cause you only need basic hosting, not some complex nodejs compiling server.
I created a starter kit http://redux-minimal.js.org/ which helps you create rich real-world apps with the minimum amount of packages and very light configuration setup. If you look at the folder structure you can see that the app uses the index.html from the public folder, and then the css and js file are compiled directly in the public folder. Which makes it easier to just copy the public folder to what ever server you want.

Related

nodejs - install production build of reactjs app on offline server, then set up to run as a service

I installed the following package globally using
npm install -g serve
on my development PC which has internet. It is currently the only package installed globally on my PC.
https://github.com/vercel/serve#readme
After I compile and create a build folder, i run the following command to have the production version of code run using HTTPS.
serve -s build --listen 3000 --ssl-cert "/my/cert/server.crt" --ssl-key "/my/key/server.key"
Ok, so here comes the problem. I have to run my code on a server that is not connected to the internet. I've copied and moved the global node_modules folder over to the server and confirmed the permissions are the same between the server and dev pc. I also confirmed that the package is seen as installed on the server by:
npm list -g --depth=0
When I run the serve command above on the server, it has no clue what serve is. CentOS complains about
bash: serve not found...
So, I added an alias to the ./~bashrc file on the server (which I also had to do on my dev pc and reloaded:
vim ~/.bashrc
export PATH="$(npm bin -g):$PATH"
source ~/.bashrc
I found the export command in another SO post, and it worked on my dev pc, however linux still does not recognize the serve command. I also need to know how to determine how to run this command from within a service, which means I also need the absolute path of the "serve" command.
I'm kinda stuck on this, since all the articles online only talk about how to run "npm start" as a service, which I can do for a development build of software with no issues. I cannot find anything on how to set up a service for a production build.
I dont 100% need to use serve, but my other coworker is using it for his project, which has internet access.
I've even gone as far as trying to piece together the location of the main js file in the module:
/path/to/node_modules/serve/build/main.js -s build --listen 3000 --ssl-cert "/my/cert/server.crt" --ssl-key "/my/key/server.key"
This will allow me to start the service, but then I get all kinds of cross site scripting errors from my apache backend server.
Any help would, as always, be appreciated! Thanks!
Disregard,
When I ran npm install -g serve on the pc with internet, it created a soft link to the serve module. I discovered this by running the following on my dev pc:
which serve
I created that soft link on the offline server, and it appears to be working.

How to apply Node.js secuirty updates?

How to apply node.js security patches?
Is there a specific process to apply security patches when using meteor js on ubuntu 16.04?
When you're running meteor in production mode, it is run as a (pure) node.js app. So the short answer to your question is to just update node (depending on how you installed it; probably sudo apt-get update -y && sudo apt-get install nodejs -y).
There are a variety of tools you can use to deploy a meteor app (e.g. meteor-up), but all of them have essentially the same two steps, which are easy enough to do yourself:
Bundle your meteor app into a node.js app
meteor build ../my-build-output-folder --server https://my.production.site.url --architecture os.linux.x86_64
This will create a meteor-server.tar.gz file in the folder you specified, containing the node.js app. The process is then (as per the README file that is included in the bundle):
Transfer the meteor-server.tar.gz file to your server
tar -zxvf meteor-server.tar.gz to extract the node application
The included README file tells you the rest :
README:
This is a Meteor application bundle. It has only one external dependency:
Node.js v8.11.4. To run the application:
$ (cd programs/server && npm install)
$ export MONGO_URL='mongodb://user:password#host:port/databasename'
$ export ROOT_URL='http://example.com'
$ export MAIL_URL='smtp://user:password#mailhost:port/'
$ node main.js
Use the PORT environment variable to set the port where the
application will listen. The default is 80, but that will require
root on most systems.
Set up a system to survive restarts e.g. upstart , pm2, supervisord , or docker

Deploying my node.js app from Github to a VPS

I have an node.js application on Github. I have never done any VPS deployment before and I am learning on the go.
I am using the VPS by Hostinger.in, the OS being used is Ubuntu 14.04. So far this is what I have done:
Connected to their SSH successfully from my Terminal
Installed node.js on the server [https://www.hostinger.com/tutorials/vps/how-to-install-node-js-on-ubuntu]
Installed Git on the server [https://www.hostinger.com/tutorials/how-to-install-git-on-ubuntu]
I could not find any online resources for deploying my node.js to Hostinger VPS so I am following the ones written for DigitialOcean.
The one tutorial I followed is this: https://code.tutsplus.com/tutorials/setting-up-continuous-integration-continuous-deployment-with-jenkins--cms-21511
I cloned my repository doing:
git clone https://github.com/myusername/node-project.git
and it seems it was deployed (didnt give me any errors).
All the installations I did on the server I did as the root/admin user. So far I have not created any separate user to perform any of these tasks.
The server hostname given to me is dangerous-pigs.com. Now I am assuming my node.js application is deployed, but when I go to dangerous-pigs.com it shows me server not found error.
I also installed forever for my node app and when I run
forever start app.js
it says:
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info: Forever processing file: app.js
error: Cannot start forever
error: script /root/app.js does not exist.
Which means the app is either not installed or installed somewhere other than the root folder.
There is a lot going on and I am confused where to start fixing issues.
How can I deploy the app to running it on the dangerous-pigs.com?
Update
So it seems I have to go inside the project folder in root and do the
npm install --production
after which I did
node app.js
The server seems to be running but, I can only access my application if I do to the actual IP provided by the service.
So if I type http://93.188.163.249:8000 --> that's my application.
How do I change it to point to a domain?
After some more research this is what I found:
Currently by default Apache2 runs on port 80. To run nodejs on port 80 first I need to install libcap2-bin in my Ubuntu server by doing:
sudo apt-get install libcap2-bin
after which I do
sudo setcap cap_net_bind_service=+ep /usr/bin/nodejs
the above command works if you have a mac, for windows the command maybe
sudo setcap cap_net_bind_service=+ep /usr/local/bin/node
but please confirm before doing it.
Also your nodejs server needs to be stopped before you make these changes else it will not work. In my case I had forgotten to stop my node server and kept running the sudo setcap command but it did not changed the port (for obvious reasons).
If you are using forever to run node then do:
forever stopall

How to run my express app on digital ocean droplet

I have a droplet on Digital Ocean and I spent quite some time setting it up by following their tutorials and all that. Then I SFTP'd my app to my server and it got transferred and everything then I ran sudo npm start and the console says that it's running but when I visit http://share3na.com as you can see nothing shows up. I installed all of the modules by running sudo npm install --save [module] then after manually doing all of them just to be sure, I ran sudo npm install.
I also changed the name servers in my domain.
In Digital Ocean,
Initially we buy a droplet. Later we have to choose the operating system to be installed, in your case you have chosen Linux maybe Ubuntu.
First, set your ssh access and configure ssh if needed
Later we have to update the package manager by using sudo apt-get update
Copy the NodeJs app into your droplet.
Set up the NodeJs by installing its dependencies and configuring the database etc.
Configure Nginx for the your NodeJs app and also add SSL certificate if any to the nginx.
Restart Nginx after configuring it.
Run your NodeJs app.
You should be able to access your NodeJs app if the Nginx is configured correctly.
Hope this helps.

I can not use grunt -cli and grunt serve in my web hosting

I have developed a website on Node.js that runs perfectly on my local machine. I run my server with the command:
$ grunt serve
The problem is when i run my web application on my server online ( gandi server ). I can't use the command
$ grunt serve
Because i should install the package '' grunt-cli ''wich :
$ npm install -g grunt-cli
On server Gandi.net, i can't install global package, then i don't use the command
$ grunt
I try a program like
var grunt = require('grunt');
grunt.task.run("serve");
Program don't run.
I need help for run my grunt task '' serve '' without grunt -cli
Option 0
grunt is a build tool and is generally not used to run servers other than local test servers. So the best solution is probably to get your server up and running using pm2 or forever or something else instead of grunt.
As far as getting grunt running on the server, if you still need to do that, you have a few options.
Option 1 is the least disruptive to the system but may require the most understanding on your part to pull off successfully. Specifically, I'm not sure how much grief you will get from grunt if it finds itself in a non-global path.
Note that Option 1 doesn't require superuser privileges.
Option 1
From a shell in your home directory, you can install grunt-cli in without the -g. Then use a shell alias or your PATH environment variable so that you run grunt from ~/node_modules/.bin/grunt.
Option 2
If you have superuser privileges, change the permissions on the global node_modules directory so that you have write access to it.
Some people recommend this over the next option for security reasons, but I think most people probably just go right to...
Option 3
If you have permission to do so on your server, you can use sudo npm install -g grunt-cli.
Option 3 is the easiest but also requires the most trust in the packages that you are installing. Because a package can do anything once you start installing it with sudo, only use this option on packages you inspect and/or trust.

Resources