How do you deploy api made with express in create react app - express

I have a simple api created with express.js. When ever i try to push to Heroku it get stuck at this point?
remote: [4/4] Building fresh packages...
remote: Done in 16.30s.
remote:
remote: -----> Build
remote: Running build (yarn)
remote: yarn run v1.22.4
remote: $ node server.js
remote: Server started on port 9000
I also see the same thing in heroku dashboard "View build progress"
here is my package.json
{
"name": "firebase-server",
"version": "1.0.0",
"main": "index.js",
"repository": "##########",
"author": "#######",
"license": "MIT",
"scripts": {
"start": "nodemon --ext js,graphql --ignore data/ server.js",
"build": "node server.js"
},
"dependencies": {
"#firebase/app": "^0.6.7",
"#firebase/component": "^0.1.15",
"apollo-server-express": "^2.15.1",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-jwt": "^6.0.0",
"firebase": "^7.15.5",
"graphql": "^15.3.0",
"jsonwebtoken": "^8.5.1",
"notarealdb": "^0.2.2"
},
"devDependencies": {
"nodemon": "^2.0.4"
}
}
the only thing i have in this project is my server.js. what am i missing or not doing. Basically i trying to deploy this to have a live API for my project. it is working locally but now i would like to have it working live on heroku.

With Heroku, the build script is used if you need to customize your build options (e.g. if you're using WebPack or TypeScript). The issue is that you're using a script called build, which you're expecting to start the application. It's running that script, as it promises to do, but since it's starting the application, it'll "hang forever" from your point of view.
If you change your scripts to this, I think this will solve your issues. Locally, you would use npm local for nodemon, and npm start would start the app on Heroku.
{
"scripts": {
"local": "nodemon --ext js,graphql --ignore data/ server.js",
"start": "node server.js"
},
}

Related

cant deploy vue app in docker with parcel

Not able to load vue in docker container, using parcel.
Vue is not loaded, and vue devtools cant find vue. All files seems to be in devtools/sources.
Its working outside of docker with npm run dev.
JS error:
Uncaught TypeError: Cannot read property 'props' of undefined
at vue.common.prod.js:6
Dockerfile:
# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package.json /app
RUN apk add --update npm
RUN apk add util-linux
ENV FONTAWESOME_NPM_AUTH_TOKEN XXXXX
COPY .npmrc /app
RUN npm install
RUN npm audit fix
COPY src/. /app/src
COPY index.html /app
RUN npm run production
# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
package.json
{
"name": "myapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"alias": {
"vue": "/node_modules/vue/dist/vue.common.js"
},
"scripts": {
"dev": "parcel index.html",
"production": "parcel build index.html"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#fortawesome/fontawesome-pro": "^5.15.1",
"axios": "^0.21.1",
"bootstrap": "^4.5.3",
"bootstrap-vue": "^2.21.2",
"faker": "^5.1.0",
"jquery": "^3.5.1",
"lodash": "^4.17.20",
"moment": "^2.29.1",
"vue": "^2.6.12",
"vue-hot-reload-api": "^2.3.4",
"vue-router": "^3.4.9"
},
"devDependencies": {
"#vue/component-compiler-utils": "^3.2.0",
"parcel-bundler": "^1.12.4",
"sass": "^1.32.2",
"vue-template-compiler": "^2.6.12"
}
}
I think I can probably get your dev server going.
I think parcel's default port is 1234. So you need to tell it to be on port 80. Also hot-reloading wont work unless you specify and expose the ws port that it
Change your package parcel run command like so.
{
...
"scripts": {
"dev": "parcel index.html -p 80 --hmr-port 33333",
},
}
Then add this to your Dockerfile
...
EXPOSE 33333
That should allow parcel to connect to the parcel dev server

Once i create and use own module then it will gives error like: Unable to resolve module

I am new in react-native and I have, for the first time, created my own module(npm).
I have tried to create my own module(npm) for common components and individually it works fine. However once I install, link it in our app, and try to use those components, it gives an error like this:
Unable to resolve module `<Module-name>` from `<file>`: Module `<Module-name>` does not exist in the Haste module map.
(Note: I have tested using Android Emulator only)
I have followed the below steps for module and test app creation
For Module
react-native init <module-name>
Add simple code of component in main index.js
And set pacakge.json like this:
{
"name": "<module-name>",
"version": "0.0.1",
"private": true,
"main": "index.js",
"scripts": {
"start": "react-native start",
"test": "jest",
"lint": "eslint .",
"build": "echo 'build script executed'"
},
"dependencies": {
"react": "16.8.6",
"react-native": "0.60.4"
},
Now I check this component (react-native run-android), it will work fine.
Now I have tried to use in an app with the below steps
For Test App
Create new fresh app (react-native init <app-name>)
Install created npm with full path like;
npm install <full path of component>
Now I try react-native link <full path of component>, I have also tried simple react-native link, but nothing happens.
Now I run app using react-native run-android, however every time it gives the same error like;
Unable to resolve module <created-module name>
test app package.json
{
"name": "<app-name>",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"react": "16.8.6",
"react-native": "0.60.4",
"react-native-my-library": "^1.0.2",
"<created-module-name>": "file:../<created-module-name>"
},
"devDependencies": {
"#babel/core": "7.5.5",
"#babel/runtime": "7.5.5",
"#react-native-community/eslint-config": "0.0.3",
"babel-jest": "24.8.0",
"eslint": "6.1.0",
"jest": "24.8.0",
"metro-react-native-babel-preset": "0.54.1",
"react-test-renderer": "16.8.6"
},
"jest": {
"preset": "react-native"
}
}
Created module successfully installed but I think it is not linked properly and it will gives error.
So what is wrong here ?
Please give me suggestion / help.
Thanks.
I am assuming your module is successfully published in npm repository. Otherwise you can not use npm install <full path of component>.
If you are using
npm install <full path of component>
command for installing your module to a Test App from npm repo. Specify in your package.json like
"<created-module-name>": "file:../<created-module-name>"
is wrong. You need to remove that line from your package.json and try to install like;
npm install --save <full path of component>
This will automatically create a line in your package.json. You can now manually link your module.
For manual linking you can follow that guide.
Edited:
If you are using in your local computer,
Then no need to npm install.
Just copy your module into your project node_modules folder.
Then in you package.json add;
"dependencies": {
...
"your_module_name": "your_module_version"
...
}
Then, you just follow the manual linking process that I mentioned above.

'gatsby build' failing in Travis CI - error #98123 WEBPACK

I'm trying to deploy my portfolio website using AWS S3, CloudFront, CodePipeline, and Travis CI.
Everything works fine, but Travis CI build keeps failing.
gatsby build gives me an error with:
error #98123 WEBPACK
Generating JavaScript bundles failed
This question is very similar to mine, but the solution was irrelevant to mine because I don't have yarn file and I tried reinstalling my npm dependencies.
Here is the copy of my logs:
Generating JavaScript bundles failed
Can't resolve '../components/Layout' in '/home/travis/build/stomg7969/react-portfolio/src/pages'
File: src/pages/index.js
See our docs page for more info on this error: https://gatsby.dev/issue-how-to
error #98123 WEBPACK
Generating JavaScript bundles failed
Can't resolve '../components/Layout' in '/home/travis/build/stomg7969/react-portfolio/src/pages'
File: src/pages/404.js
See our docs page for more info on this error: https://gatsby.dev/issue-how-to
The command "gatsby clean && gatsby build" exited with 1.
store build cache
Done. Your build exited with 1.
And here is my package.json.
"name": "gatsby-starter-spectral",
"version": "0.0.1",
"description": "Gatsby.js V2 starter template based on Spectral by HTML5 UP",
"repository": {
"type": "git",
"url": "git+https://github.com/anubhavsrivastava/gatsby-starter-spectral.git"
},
"author": {
"name": "Anubhav Srivastava",
"email": "anubhav.srivastava00#gmail.com"
},
"dependencies": {
"gatsby": "^2.13.39",
"gatsby-plugin-manifest": "^2.2.3",
"gatsby-plugin-offline": "^2.1.0",
"gatsby-plugin-react-helmet": "^3.0.12",
"gatsby-plugin-sass": "^2.0.11",
"node-sass": "^4.12.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-helmet": "^5.2.1",
"react-images": "1.0.0",
"react-scrollspy": "^3.4.0",
"smoothscroll-polyfill": "^0.4.4"
},
"scripts": {
"develop": "gatsby develop",
"build": "npm run clean && gatsby build",
"deploy": "npm run clean && gatsby build --prefix-paths && gh-pages -d public",
"serve": "gatsby serve",
"clean": "rimraf .cache public",
"format": "prettier --write '**/*.js'",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"gh-pages": "^2.0.1",
"prettier": "^1.17.0",
"rimraf": "^2.6.3"
},
"keywords": [
"gatsby",
"gatsby-starter",
"gatsby-starter-spectral"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/anubhavsrivastava/gatsby-starter-spectral/issues"
},
"homepage": "https://github.com/anubhavsrivastava/gatsby-starter-spectral#readme"
}
Lastly, this is my .travis.yml file.
language: node_js
node_js:
- 11.8.0
install: npm install
script: gatsby clean && gatsby build
deploy:
provider: s3
access_key_id: $AWS_KEY
secret_access_key: $AWS_SECRET
bucket: 'thedevelopark.com'
skip_cleanup: true
acl: public_read
local_dir: public
Thank you in advance for your feedback.
I've had the same problem and tried and checked case-sensitivity a thousand times. Wouldn't do anything.
Then I changed the name of the component in all areas, filename, import, export, you name it. Now it works.
I don't know if Netlify had a problem with my component's name "Socials"? Guess I'll never find out.

How to push to netlify in production mode [Nuxt JS]

I have my app created with nuxt js. I just want to push my app on Netlify.
So firstly i configure my deploy settings :
Repository on git
Base directory : Not set
Build command npm run build && npm run start
Publish directory .nuxt/dist
My app is build correctly but npm run start just launch on localhost:3000
I decided to modify config Host, I don't know if it's the best solution ?
{
"name": "app-nuxt",
"version": "1.0.0",
"description": "My remarkable Nuxt.js project",
"author": "wyllisMonteiro",
"private": true,
"config": {
"nuxt": {
"host": "https://mywebsite.com"
}
},
"scripts": {
"dev": "HOST=localhost PORT=3000 nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"test": "jest"
},
"dependencies": {
"#nuxtjs/axios": "^5.3.6",
"cookieparser": "^0.1.0",
"cross-env": "^5.2.0",
"js-cookie": "^2.2.0",
"nuxt": "^2.4.0",
"vee-validate": "^2.2.0",
"vuelidate": "^0.7.4",
"vuetify": "^1.5.5",
"vuetify-loader": "^1.2.1"
},
"devDependencies": {
"#vue/test-utils": "^1.0.0-beta.27",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^24.1.0",
"coffee-loader": "^0.9.0",
"coffeescript": "^2.4.0",
"jest": "^24.1.0",
"node-sass": "^4.11.0",
"nodemon": "^1.18.9",
"pug": "^2.0.3",
"pug-plain-loader": "^1.0.0",
"sass-loader": "^7.1.0",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2",
"vue-jest": "^3.0.3"
}
}
I want to launch in localhost:3000 by executing npm run dev
AND https://mywebsite.com by executing npm run start
Can you tell me if there is some modifications in my package.json or in my deploy settings on Netlify
For anyone that stumbles across this in the future, the problem you're experiencing is due to a misunderstanding with what services Netlify offers.
Specifically, they are primarily a static site host, which means they will host your built files, and serve them for you. They will not run your server, which means nuxt start will not run.
Instead, you should be using nuxt generate to generate the static files of your app, and telling Netlify where the output folder is.
For example, the "build settings" on Netlify:
Repository github.com/example/example
Base directory Not set
Build command npm run generate
Publish directory dist
This will properly deploy a Nuxt app, assuming you haven't changed the default build folder. For clarification, the .nuxt folder contains both client and server files, and can only be used when running your own Nuxt server on an instance of some kind.
As it looks you need to tweak your deployment command. Go to Netlify and try changing it to npm install; npm run build. This should resolve the problem.

nodemon not working

When i run nodemon, it shows
[nodemon] 1.17.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node app.js`
But when i run npm start, everything works fine. Why is nodemon not working
my package.json
{
"name": "sarthakmedia",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "^1.18.3",
"cookie-parser": "~1.4.3",
"cors": "^2.8.4",
"debug": "~2.6.9",
"express": "~4.16.0",
"express-mysql-session": "^1.3.0",
"express-session": "^1.15.6",
"git": "^0.1.5",
"http-errors": "~1.6.2",
"jade": "~1.11.0",
"morgan": "~1.9.0",
"mysql": "*",
"nodemon": "^1.17.4",
"pug": "2.0.0-beta11"
},
"description": "practise",
"main": "app.js",
"devDependencies": {},
"author": "Anita",
"license": "ISC"
}
The api's don't get called at all. nodemon starts fine though
try this
first step
in package.json file
"scripts":{
"start":"node app",
"dev":"nodemon app"
}
second step
install nodemon as devdependencies
using code npm i -D nodemon
3)in app.js file
const express = require("express");
const app = express();
// routes
app.get("/",(req,res)=>{
res.send("hello");
});
// server started
const port =process.env.PORT || 5000;
app.listen(port,()=>{
console.log("server started at port 5000");
});
4)fourth step
use (npm run dev) in command line tool
Nodemon starts by running the file ./app.js.
But your start npm script (which works according to your question) runs a different file ./bin/www/index.js.
I think you should tell nodemon what file is your entry point.
Thus, you should edit the "main" entry in your package.json with the same value, e.g., ./bin/www. In fact, nodemon reads this value in your package.json in order to know what file to start with.
Just run your app with nodemon -w ./ when you are in app root directory.
-w stands for looking at the directory rather than 1 JS file. It is usefu; when you have more than 1 js you need to mon