How do Node.js and Laravel fit together - node.js

I'm doing the courses at Laracasts and the command npm install && npm run dev is used. This didnt work from my htdocs/projectname directory so I installed the windows 10 node.js installer, which installed it to a program files directory.
Somehow, it seems node.js ended up in my packages.json
Node.js seems to be all javascript on the server side? How does this work with Laravel?
Thanks!

NodeJS can be used for many things, which include server-side code, as well as provides tools to be used in a development environment, which are available through the NPM Repository. A quote from the NodeJS Wikipedia page states the following:
Node.js is an open-source, cross-platform, back-end, JavaScript
runtime environment that executes JavaScript code outside a web
browser.
A standard Laravel installation includes a package.json file as standard, which includes the commands and requirements for various packages, one of which includes laravel-mix, which is a webpack based tool for optimizing and compiling your assets (Typically Stylesheets and Javascript).

NPM ist the Node package manager. It's installed with Node.js.
You can use npm -v in the CLI to check if it's installed correctly.
In your project directory must be a package.json to use npm install && npm run dev.
In case of Laravel a package.json should be in the directory.

Related

Is there a difference between using npm and node.js?

I'm using npm to download libraries.
Is it correct to say that I'm using node.js ?
NPM is a package manager for Node.js packages, or modules.
NPM hosts thousands of free packages to download and use.
The NPM program is installed on your computer when you install Node.js
Node.js As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications.
https://nodejs.org/en/about/
Node.js is all about modularity, and with that comes the need for a quality package manager; for this purpose, npm was made. With npm comes the largest selection of community-created packages of any programming ecosystem, which makes building Node.js apps quick and easy.
https://nodejs.org/en/docs/meta/topics/dependencies/#npm
Hope I helped you see the differences.Best Regards !
Yes nodejs is a runtime environment for javascript docs here like JRE is for java. You can use Node to run javascript in you system otherwise you need a browser to run it
NPM is a library for javascript read here, you use that to install libraries incase you need to use some extra features you dont wanna code yourself
Nodejs can run w/o use of npm like you can use other library repo like yarn likewise you can use other run time environment like Deno and use npm with that w/o using node

NPM versions during development and production

From what I have read it is a good idea to use the same version of Node.js throughout the development and production phases of an app.
Is this also true of NPM? It looks as if NVM is keeping specific versions of NPM together with specific versions of Node.js inside the .nvm directory. However, although I can see from the NVM documentation how to make sure you run an app with a particular version of Node.js, I can not see how to make sure that a particular version of NPM is used for a particular app. For example if I run the command npm install package from the root directory of an app I think it will use the default version of NPM not the specific version associated with the Node.js version specified in the .nvmrc file of the app.
Do I need to be consistent in the version of NPM I use during app development and production? If the answer is yes how do I achieve that?
When we start a Project using Nodejs a file named package.json is created automatically and it keeps track of all the dependencies in the ongoing Project. So you do not need to worry about the versions, you just have to start the project and all the dependencies will be taken care of.
Suppose you need to share your codes(like Git) then you just need to share your codes and package.json file that will do the trick.

Angular2 development Without node and npm

I am new angular2 development, and what i came to know is before starin the angular2 development, I must install the nodejs for server and npm to download dependencies from official documentation.
I succesfully deployed the source code in tomcat sever[by build]
So my Question is after installation and creating the new project, i got node_modules. By using these node_modules(can i start development of angular2 on another i.e a new machine where node & npm is not installed)
Basically my question is.. I want to start development of angular2 by using the project structure on new machine. Without the installation on node & npm
From Angular docs
Node.js and npm are essential to Angular development.
If you built/compiled the app and have all the modules installed (you have your node_modules) folder then its just javascript and html which you can run on any server you want.
For npm, if you need any modules/packages, I think you can manually download the package and add it to your development environment. But what if the process needs to be automated? You can't just sit there and download all the packages from github. So npm is really helpful when it come to this. You only need a file containing all dependencies, and run it at build time (package.json)
About nodejs, nodejs allows you to run javascript on the server when you need any interaction with the database. So why don't we just go with the easy way?

How to zip a nodejs server app?

I have to create a zip file of my whole nodejs server app.
I should be able to unzip it and run it, without installing dependencies and apps.
It should not be a binary file.
The dependencies should be flattened.
How to do this thing ?
Generally, a Node.js app has its dependencies installed in the node_modules directory in the project root.
So, after running npm install (or npm install --production), you should be able to zip up the project directory and that should be all you need.
If any of your dependencies in node_modules are native addons, then you will not be able to install them on a different architecture or OS. If there are native addons, you will also want to make sure your target machine has the same version of node installed as the machine where you created the zip file. (It's a good idea anyway, if you can, to make sure the node version on the target machine is the same as the source machine.)
One obvious requirement of the target host if you do as I describe above is that node is already installed there. Not sure if that's OK for your use case or not, but sounds like it probably is?
Thank you, all of you for your help.
I got the solution for my question.
I am using npm pack to pack the nodejs app.
To pack nodejs app with some dependencies like morgan, express we need to use npm bundle it helps to include the other module required for node js app.
With this, we don't need to perform npm install.
We just have to install bundle and then include bundleDependencies field including the name of required module in package.json.
And then perform then run the command npm pack. It will create a tar file just copy this file in other folder and uncompress it and run the server starting file.
The place where you are going to run the nodejs file, there nodejs app should be installed
I think you might be looking for this: https://github.com/nexe/nexe
Nexe is a command-line utility that compiles your Node.js application into a single executable file.

What is the difference between node.js runtime and npm package manager options while installing node.JS?

I am trying to install node.js by downloading the .exe file, I am confused and stuck on the Node.js setup where in it asks to install node.js runtime or npm package manager so I want to proceed through the installation after knowing fully the difference between the two.
My question is what is the difference between node.js runtime and npm
pacakage manager and what are all the features do I get on the two
options.
My basic purpose of installing node.js is to compile Typescript, Please help me to understand the features of the two package
First of all, it does not ask you to install Node.js runtime OR npm package manager, it offers you to install them both (if you want)
Now, Node.js runtime is basically what will understand your javascript code and execute it to produce a result.
Npm package manager is a tool which will allow you to install third party libraries (other people's code) by using the command line.
npm install express
will install the framework called express for example.
Node JS
Node.js is a platform built on Chrome's JavaScript runtime for easily
building fast, scalable network applications.
Real-Time services (Chat, Games etc)
NPM
Npm is a package manager. Typically this software is installed to
build Node applications.
It let's you install software (libraries, plugins, frameworks and
applications).
Node.js or Node is an open-source, cross-platform, JavaScript runtime environment(JSRE) that executes JavaScript code outside of a web browser.
npm is a package manager(like Nuget package manager in .NET -Microsoft ) for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js.
You can differentiate them by finding their version using below code.
node --version
npm --version
node is a framework that can run JavaScript code on your machine while npm is a package manager. Using npm we can install and remove javascript packages also known as node modules. Now, it is not a rule that you should use npm to install and remove node modules. We can use yarn also. npm and yarn are capable of the following:
Read and understand package.json file
Download and put javascript modules in node_modules folder.
Run scripts mentioned in package.json such as starting a node server, running in dev and production mode, running scripts for unit testing etc.
npm by default run node server.js; if you didn't specify scripts in the package.json
"scripts": {
"start": "node your-script.js"
}
Which means npm run node
if you need use yarn, you'd better choose node.js runtime, usually the default choice is a better one for beginner //TAT

Resources