NestJS server dies when console is closed? - node.js

I created folder for project, copy package.json and run npm install, build locally nestjs project and copy dist into server. Then ran in console node dist/main.js. For testing I used a base NestJS project (nest new ...) which only return "Hello word" on 3000 port.
Server work fine, but after close of console will stop.
I think problem on VPS (Ubuntu) settings or may be need to add some parameters to NestJS.
Why it not work constantly?
Thanks in advance for any advice.

I resolved problem with npm forever - https://www.npmjs.com/package/forever
install it globally - npm install forever -g
then got to project dir and run - forever start dist/main.js
Seems all work fine.

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.

Is it okay to do an npm install on another terminal window while nodemon is running?

Let's say I am working on an app that listens on port 3000. Nodemon is running. I require another npm package in the app.js file, and on another terminal window that is open to the directory of that app, I run npm install (package name).
Will this cause any issues?
I've just tested this case on Node.js project and turns out that installing additional library while nodemon was running from the secondary terminal doesn't cause any issues. After installation was complete, nodemon picked up changes and reloaded application.

NodeJS close server and start again

I am brand new to React and NodeJS. I have NodeJS latest version installed on my mac as well as React. I can start and run the app using npm start I am following tutorials and it was fine and I could see my app in the browser. The problem begins when I need to finish for the day and start again the next day and I do not know how to start the server again and app and to continue the work. npm start does not work. Unfortunately tutorials only show how to start the app for the very first time, but they don't show what do you need to do to interrupt your work, shut down computer and continue the following day. What steps do I need to take in to continue my work the following day?
regarding your question the things you want to make sure that whatever project you are working on (nodejs or react) that you cd into the project folder before you run any commands as these scripts you are running "npm run start" etc.. are based on what scripts are written inside the package.json.
so if you use create-react-app for reactjs the "npm run start" is a default script that comes with CRA and will run the app for you.
for express you can also check the scripts and there will be something similar but you can do "node server.js" (or app.js depends on how you called the file you initialize the server) and it will run the server.
in summary:
make sure to cd into the correct directory
check package.json for scripts if you are not sure what they are
also run "npm install" as you might have some missing dependencies
enjoy.
If you have any more questions will edit my response to answer those as well, have a nice day ;)
Just look for error messages in the Terminal when you run npm start. Try to understand them and fix them.
You can also install Nodemon (npm i nodemon) and run nodemon {filename}.js to start the server. {filename} is the name of the file in which you're starting the server.

reactjs app not run after serve and start

I just installed node.js on my centos 7 server, then install react
it successfully created my new react app, after that, I run:
npm start
and or serve -s build
but none of these run in my browser.
This site can’t be reached
how can I solve this?
If you have sever inside can you try with start debugging of your application
Stop npm, if you're using yarn
Start the project with command above, inside your project home folder
yarn start
Take some time to learn commands below:

Node js Application- Getting 'command not found' after connecting project to github

I made a node js application and I was using nodemon to restart the server whenever I made changes, I made a repository on github and connected my node project. Now I can't run nodemon because it says command not found. I'm not sure about how to fix it.
install nodeman globally and try again,
hopes you do have configuration file and package.json
npm install nodeman -g

Resources