Deploy react redux starter kit on Heroku - node.js

I downloaded the starter kit for react and redux. It's really nice and works fine in localhost with the command npm run dev but I'm not able to deploy it on the server.
First, I use the command npm run deploy which clean and compile my src folder in the dist folder. Then, I deploy the server on Heroku. Once all is built, the server run npm start which execute the command babel-node bin/server. This command is not recognized by the heroku server.
I would really appreciate if someone could help me to debug this. I tried to clone again the repo, then :
npm install
npm run deploy
Publish on Heroku and I have the same error without changing anything on the code.

The reason it doesn't work on heroku is because there isn't any production server ready in this project for your deployment as specified here : https://github.com/davezuko/react-redux-starter-kit#deployment
When you run the npm run deploy command, all the front-end code is compiled in the /dist folder.
In order to deploy it on heroku you need to :
Create a very simple http server always serving the file index.html. Here is the main part using Express or Koa
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/dist/index.html'));
});
Modifying the npm start script in order to target this new production ready server.

Related

Install React JS on Cent OS

I am very very new to React JS and have tried to install it on my VPS server that is running Cent OS.
Node.js seems to be working,
I have build a React project using the following code as a root level user on SSH:
npx create-react-app my-react-project
cd my-react-project
npm start
but when trying to view in browser I get a blank page (instead of react js default template)?
I see many people install this locally but I haven't found any examples on a hosted VPS, is this something I am doing wrong?
Any help would be much appreciated, thanks!
if you have ssh access to your VPS, the rest is pretty the same as your local environment.
You can copy/paste your project to your CentOS host and use the following commands in order to run it:
cd your_project_folder_which_includes_package_json_file
npm install
npm start
Also, if you are using this server as a production host, You should consider getting a production build of your React app on your local env by running npm run build and then publishing the build folder on your server and serving it using a static file server or using a reverse-proxy such as Nginx as a static server.
Actually this page in React documentation does a good job in explaining the details of deploying a React app, I encourage you to take a look at it.

can we deploy an react js application without source(src folder) code locally

some background:this is my first react application and my assumption is build in react is similar to binary files in c++
question : this is for a react application which sole purpose is to run locally. is there anyway we can do npm start only with build
have tried to delete the src folder after building.
expected result is the app should run as usual.
actual result : app crashes saying, index.js file is missing
npm start won`t work with build version,
you need to install serve and run build using serve locally on your machine
npm install -g serve
serve -s build
ref: https://facebook.github.io/create-react-app/docs/deployment

React app deployment error in npm development build

I'm developing a react application.When I try to deploy it using npm start it is showing that your development build is not optimized.Use npm run build to install production build.
The message means exactly what it says. Use npm run build to make a production build, and serve those built static files with some http server like nginx or apache. Your current npm start is making a debug build, and probably serving it with a hot reloading server.
To identify the differences between a production build and a debug build, check out your underlying build system and its configurations.

Deployment on IIS of Nestjs application

I have tried to deploy my Nestjs deploying on IIS server. I have configured iisnode on IIS that works fine for express application but I am getting errors for missing modules for nestjs. I have tried following commands for building production package
npm run start:prod
and
npm run webpack
but failed to deploy on IIS. How can I build a deployment package?? so I can deploy. I am new with nodejs and Nestjs.
Look at the project's package.json. You'll see that start:prod is a script that runs node on the compiled output of the project. You get the compiled output by running:
npm run prestart:prod
that will re-build your app into the dist folder.
So you can
Zip up the dist folder
deploy to the target host
Unzip it
Try running iisnode on it
let me know how that works

How to deploy Nestjs App (on Azure)?

I am trying to deploy a Nestjs API (with Auth0 authentication). When I run it in VS Code with npm run start:watch server, everything's fine.
Now the question is: what should I do to deploy it on a webserver? Should I only copy the dist folder (after runnin tsc)? what about node_modules? Should I leave the port to 3000?
As a side note I am trying to deploy it on Azure but I guess the questions holds for any platform.
Many thanks!
Modify your package.json file, and add a postinstall script, this script should be tsc or tsc --sourceMap false if you would like to avoid sourceMaps from being generated.
That would make azure to run tsc after installing all npm packages, remember to change start script also, so its value is 'node dist/index.js'

Resources