Cannot build after npm start - node.js

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

Related

node dist/server.js exits without error messages

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.

Stop VS Code from opening a web browser window when I build my project in the console

I created a Hello World application using this tutorial.
When I build the application from the terminal in VS Code typing npm start VS Code or npm, no clue who, will open a new browser window... without even an url or anything in it.
Is there anyway to prevent this from happening? i.e. if I type in the console npm start I do not mind what happens but I want to avoid to open automatically a window of my browser.
Try to run BROWSER=none npm start or create an .env file with BROWSER=none. Refer to Advanced Configuration of create-react-app official docs
You can create a .env file at the root of your project and insert the BROWSER=none npm start property.
An alternative would be direct throught terminal, like this: set BROWSER=NONE && npm start
Here you can see the discussing about that.

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.

Can't seem to get Node js and NPM up and running: Reference Error on every command

I just installed node-v4.4.5-x64 and I'm using Windows 10 but everything I type into the command line (even -h and --help) gives me a ReferenceError: h is not defined. I'm just getting started trying to use NPM so i'm pretty new to this. What am I doing wrong? How can I get started with NPM?
If you are using Visual Studio 2017 run npm from Package Manager Console, not Node.js Interactive Window
The error occurs because you're running the npm commands from within the node REPL: /nodejs/node.exe starts the node REPL. The reason the error is a ReferenceError is because the variable npm is not defined within the REPL.
What you want to do is run the commands inside the terminal. You'll need to exit the node REPL by pressing Ctrl + D. You should be in the terminal now.

Run node.js package on web server continuously

I'm using a blog platform specter that starts when I run npm start. Only when I have run npm start will it show up at the site URL. If I do command-c in the terminal, it quits running the package and the site goes down until i run npm start again. Is there some way to set up the server to keep the site up continuously? Right now I have to take down the site before I make any edits and then start it back up with npm start.
One thing that you can do is to install Forever by Nodejitsu. What this does is it runs your node script on the background "forever" or until you stop the process or set a timeout limit.
To install Forever, just do:
npm install forever -g
For your case, you will want to cd into the directory that Specter resides and start forever:
cd $(specterLocation)
forever start server.js
This will start your server on the background until you do:
forever stop server.js (in directory of Specter)
forever stopall (wherever on server)
To see the list of processes started by Forever, just use:
forever list
Hope this helps!
You may want to take a look at nodemon
It will auto-restart your node application whenever it detects changes to the directory where nodemon was started.
It is available as an npm package as well (https://npmjs.org/package/nodemon).
Just make your edits with the site running. Then when you're done, stop the site and start it back up. The site isn't continually running from the files, it starts up, loads into memory, then runs from there, releasing it's hold on the files.
Or, there are any number of more robust management strategies you could implement, complete with version control, process managers, integration strategies... If you plan on growing your skills to support high volume or commercial implementations, then you should look into these things. If you're just running your personal blog and that's it, just edit your files, then restart your server process when you're done.
Use Node Supervisor. It's really easy to use and install.
npm install supervisor -g
run with
supervisor whateverFileYouWant.js
https://github.com/isaacs/node-supervisor

Resources