Setup node.js App for pubblication with PM2 - javascript

I have a node.js application that uses the python-shell module. When I start the app with the command: node server.js everything works well, including Python scripts. If I try to start the application with the pm2 start logs server command, Python scripts do not work and I get a lot of errors on PythonShell, Object.callPythonScript.
Does anyone know how to fix and how does the application normally work with the node compiler, but not with pm2?
This is the logs error:

Related

Running the server in Local Machine without showing cmd the window

I' ve created my node.js app with express, now i want to upload it on my local server machine.
I've created a bat file (I will use task planner to run this) that basically move to folder app and launch "npm run start".
The question is: There's a more correct way to this? (no cloud) and is it possible to hide the cmd window?
Putting a node.js application to production can be done with pm2. Pm2 will spin up your application and keep it alive, without having any terminal/cmd open.
Simply install pm2 globally on your machine:
$ npm install pm2 -g
Then launch your application with pm2:
$ pm2 start app.js
There are some configurations you could do, so I suggest you look at their repo

How to deploy Laravel + Nuxt application?

I have built Web application using Laravel As API and Nuxt As Front and. These 2 built desperately. When the development ongoing Its isn't an issue. Because i can run them using their own development servers. Then i have bought a VPS server for host this. Now the question in how i deploy these two apps on my VPS. Specially How i can deploy nuxt app correctly in vps. Its not static side. It is ssr app.
Essentially, you are going to need a few things:
A server (which you already have)
nginx
PM2
Node/NPM installed
The tricky part of this, is to make sure the server continues running and auto-restarts in case of a crash. PM2 solves that issue, and you can read more information on how to use it here: https://nuxtjs.org/docs/2.x/deployment/deployment-pm2
You can install it by:
npm install -g pm2
Which will install PM2 globally on your server and you'll have access to the pm2 command.
Follow the documentation above, and all you gotta do is run:
pm2 start all
This will start the Nuxt service and it will run on whichever port you've defined on your nuxt.config.js or package.json files.
Now that you've got your Nuxt instance running, you need to make sure that requests that come through the browser end up on the port that Nuxt is running on, that's achievable by using nginx's reverse proxy feature that you can read more about:
https://nuxtjs.org/docs/2.x/deployment/nginx-proxy/
That documentation provides you with an example of an nginx config file, and you shouldn't really have to change anything other than the server_name, and the proxy_pass in case you've changed the default Nuxt port from 3000 to something else.
Additionally make sure that you have allowed port 80 to be listen on your server.

Using forever command to run node.js script on heroku

So, I searched a lot before asking this here as I was not able to find a single answer related to this small problem.
I want to run node.js file on my heroku server which is on free-tier but I don't want to use node file.js. I want to use forever start file.js.
So, I did wrote the commands in my package files as well as defined a Procfile for worker: forever start file.js.
And deployed to heroku, but all the logs says that
forever: bash command not found.
Any solution ?

Cannot run express with node on Heroku

I've deployed my app on Heroku and I have an express script that should wait for a post request. I need to run it separately on Heroku. When I open the console on Heroku and type:
heroku run bash node scripts/start_express.js
I get the following error:
/app/.heroku/node/bin/node: /app/.heroku/node/bin/node: cannot execute binary file
How do I use node to run my js file on Heroku?
The node buildpack for heroku will automatically look for npm start script in your package.json file. That is where you can specify which file to serve up. Check this article out for some help on node and heroku https://devcenter.heroku.com/articles/nodejs-support

Debugging node js in Webstorm when running from gulp

I'm fairly new to this, but I really tried my best looking for up for answers.
I used yeoman to generate an application. (used 'angular fullstack' - https://github.com/angular-fullstack/generator-angular-fullstack)
It has a gulpfile.babel.js config file, which runs nodemon.
What I'm trying to do is to make the gulp serve nodemon instance to hit the Webstorm breakpoints I have.
What I've tried so far :
-- Regular debugging. (trivial..) But it seems node sends excpections when he meet ECMA6 syntax. (Still.. I rather run the gulp instance than run it from webstorm.)
-- Using --debug
-- Using 'remote debug' in webstorm.
-- Setting up node inspector in gulp task and set him to listen 5353
-- Using --debug-brk and debug on port 5353 (for example)
I could really appreciate it if someone could help me.
This guy here says Webstorm can't handle this case, but it's weird, you can debug remote servers but you can't debug gulp nodemon server instance?
Debugging node app in WebStorm when run from gulp
Assuming you are using Node.js. It provides node inspector to debug the server side files on the chrome browser itself, with similar experience given in browser debugging.
Here is the reference link to set up the node inspector.
Following are the steps to set node inspector.
1) Install node inspector with command
npm install -g node-inspector
2) Start node inspector
You can start it from any directory
node-inspector
As a result, you will receive a url to debug in browser
3) Restart the node server in debug mode
change the directory to the server folder of your project
cd /path/to/your/project/directory/nodejs/server
node --debug server
4) once the server is started in debug mode successfully, copy the url received in above result and open it in Chrome browser. There you can see all the server side files of Node.js on the source section of the debugger, where you can apply the breakpoints on the server javscript files those have been written.

Categories

Resources