Initialize server.js IONIC 1 to run in "production"

Asked

Viewed 118 times

1

THE SERVER.JS SHOULD BE STARTED AS SOON AS I RUN IT ON MY MOBILE ?

How could I set you up to work that way?

This is because I have a service in Mongo, and it needs to be run the connection to Mongo which is implemented in server.js

Figura 1

1 answer

2

Do the following:

  • In his package.json look up the section scripts
  • Add this line (if any replace)

    scripts: {
        "start": "ionic serve && nodemon server.js"
        //Outros scripts aqui abaixo
    }
    

Ai then at the root of your project simply run npm start

  • Hello @khaosdoctor @Ricardo-moraleida! includes the script as suggested. but when I run npm start, first it runs Ionic serves. only after I quit, is the nodemon server.js. left only nodemon server.js , it works too. running only the server.js When running Ionic emulate Ios, the application opens. but when I click on the button that will make the connection with Mongo simply does not work, because it seems that the server.js has not been launched

  • Try to use & instead of && then it will run things in background.

  • did not work. remembering that I am using IONIC 1

  • But are you running npm start? What is the sequence of commands you are running?

  • true, I forgot that detail. I now ran npm start. apparently all right. ran the server. didn’t even open the app in Browse. with Ionic emulate opened the app, but did not connect to the database (did not run the server), this is because when running nodemon server.js at the prompt and trying to authenticate, it works.

  • But then you have to decide what you want with the command, the command I gave you starts the Ionic serve (if you have the & in the background, ai does not open the browser) and starts the server.js. If you want other npm script commands, just create other scrips below this and run with npm run <script>, for example npm run serve and in json serve: 'ionic serve && nodemon server.js'

  • I got in the way of asking the question . I rephrased the question. see if you can help me; @Ricardo-moraleida

  • Life, so simple. I didn’t know that you need to run this on a Node server like Heroku for example. it is necessary to structure the project so that the server.js (Node) stays on the server :) in case I used the Heroku. hugs

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.