node dist/server.js exits without error messages - node.js

I have an Angular Universal app.
I am able to run 'npm run start', which executes 'ng serve' and the live development server starts listening.
If instead I run 'node dist/server.js', it simply exits without any info or error messages.

check out the $.scripts.start field within the project's package.json file. That will tell you what command is being invoked through npm start, which might not necessarily be node dist/server.js. Default values for the start script are found here
Also, depending on what flavor of Javascript they are running, there might be a build step that you are missing.

Related

Cannot build after npm start

I am brand new to node.js and I am trying to build my app so that I can deploy it.
Right after I do npm start I cannot do anything. Sorry if the question is too obvious, but I have never used node.js before.
Cmd says that I can build my app which is what I want but I cannot type anything.
I have tried doing npm run build before doing npm start but I get an empty index.html.
These are my package.json's scripts:
After running npm start your app is running continuously. So if you want to type a new command, you would have to stop it or open a new terminal window/tab and run that command there. Just make sure you are in the same path you want to be.
In order to stop a running process (e.g. npm start) simply press ctrl + c (that is, ctrl first, keep it pressed and then press c) no matter if you are using mac or windows

Run React dev server as background process?

I've been recently experimenting with React and I want to be able to run the dev server that's initialized when you run npm start in the react app's directory as a background process on centOS so that I can continue to use the command line.
Is this possible with something like pm2? I tried various commands but couldn't get it to work, of course I can do the following "nohup npm start &" but I would much rather have all my managed processes using pm2 or some other process manager maybe?
Any advice?

How does NPM start an Angular and Typescript application?

Would it be possible to get an explanation of how npm start works?
I have an Angular 2 application written in Typescript. I enter npm start in the console and this both compiles and launches the application using Node's built in web server.
However what is the starting point for this? Which files does the npm start command read in order to compile and start the application? Also why do I use npm start and not e.g. node start? I understood that NPM was just the package manager for node itself.
What I understand so far:
I have a tsconfig.js file which tells the TypeScript compiler what to do.
I have a packages.json file which tells node which packages to download.
Where do the following files fit into this:
main.ts
app/app.module.ts - which I understand is the starting point for my application.
How do all of these components fit together to form the application?
npm start is just an alias for npm run start, which runs whatever command is in scripts.start in your package.json.
It neither knows nor cares about TypeScript, or Angular, or anything like that - it just executes whatever script it's given on the command line.

Log to node console or debug during webpack build

What is the best practice for debugging during webpack build process? Any console.log in the entry script doesnt output to node console.
As of the current version of webpack (September 2019), if you do a build instead of launch a dev server, console.log will output to std out (i.e. the node console).
Just make sure you are doing a full build (i.e. "npm run build") instead of a dev server (i.e. "npm run dev").
The dev server disables console.logs during the compile process in many circumstances, and/or the way the progress bar updates, the console.log strings are overwritten so you never see them.

Issue with Node-based Cordova Hook

I'm playing around with the Cordova hooks capabilities and I'm trying to test using a node application as a hook. In this article: http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/ it references running node applications, so I know it's possible.
I've created a simple node application that I'm using to test the before prepare and after prepare process:
#! /usr/bin/env node
console.log("this is a node module");
When I run my prepare, I get the following error:
C:\Users\jwargo\dev\lunchmenu>cordova prepare
The system cannot find the path specified.
Hook failed with error code 1: C:\Users\jwargo\dev\lunchmenu\hooks\before_prepare\test.js
I can't find any information anywhere about what an error code of 1 means here.
I've tested the node code and it runs fine with "node test.js" and when I execute test.js from the command line Windows simply launches my default editor.
So, can anyone tell me what I'm doing wrong or what I need to do to be able to execute a node application as a hook with the Cordova CLI?
Figured it out with some help from the Cordova dev team. The space in my shebang was causing the problem. I removed it and the problem went away.

Resources