Run 2 npm commands at once - node.js

I made a MERN project, and my structure is one backend folder and one frontend folder.
So, every time I work on it I have to cd to backend, run npm start, then in another tab, go to frontend and run npm start.
Is it possible to do a npm init in the root folder, and create a npm start that will run both commands at once ?
I'm new to terminal.
Thanks !

There are several ways you can do :
1- You can use concurrently(npm install -g concurrently)
---> concurrently "command1 arg" "command2 arg"
the most developer use these ways.And i know just these ways.

You can use this command in your terminal :
node frontend/index.js & node backend/index.js
or
npm start --prefix frontend/ & npm start --prefix backend/
You may have different paths to your files

Related

react doesn't allows to edit in node_modules folder?

I tried to run npm start on the terminal but this error including with many errors came in the terminal.
i 「wdm」: wait until bundle finished: /
C:\adrosonics_main\KM\km_admin_portal_revamping (3)\km_admin_portal_revamping\node_modules\loader-runner\lib\LoaderRunner.js:133
I expect to start the server.
Please follow these steps.
Delete the node modules
Run npm cache clean
Run npm install
Lastly npm start

Running npm build before/after npm install

I'm not familiar with npm so I might be holding the wrong end of the shovel here...
There is a package on npm that I would like to modify and use in my own project. The package is angular-crumbs. I forked the source repo (https://github.com/emilol/angular-crumbs) into my own account (https://github.com/capesean/angular-crumbs) and then run npm install capesean/angular-crumbs -force. However, this produces a node_modules folder in my project that hasn't been built (and whatever else - as I understand it) with the commands in the source repo's package.json file:
"build": "npm run clean && npm run transpile && npm run package && npm run minify && npm run copy"
i.e. it doesn't have the types, the correct package.json file, etc.
So my question is, how do I get the properly-built files (including type definitions, etc.) from my own repo to install or build-after-installing in my target project?
I am not sure about what you're trying to do, are trying to work on the
angular-crumbs source code, or are you trying to use it in your own project as a dependencuy ?
Anyway, running npm install will install all your dependencies so that you can directly use them in your project, those dependencies don't need to be built after they are installed.
In your case you seem to have an angular application (which is completely different from node.js), usually to start an angular app you can run ng serve which will build your source code and run an angular server so you can access it on localhost.

Nodemon aequivalent to npm run dev

I've just started using the whole javascript and node.js environment. To start an existing project I run three commands
npm install, npm run all and finally npm run dev to start the application in my browser.
Now, whenever I update the code I stop the current running dev via Ctrl+C, press arrow up key to get npm run dev in my terminal again and hit Enter. I believe there is a better way of doing this repetitive task, like Nodemon.
But, what is the aequivalent command for that, so that the updates I make in the code automatically become visible in the browser?
I have three files which do not work with nodeman: package.json, Gruntfile.js, app/index.js. Moreover, I tried nodemon --exec npm run dev which permanently does sth, but does not start my application.
Do you have any suggestions?
Yes, I would look at the --exec flag on nodemon. You could do something like:
nodemon --exec npm run dev
This will run npm run dev every time a source file changes. Read the nodemon NPM page to get a better idea of how to use it.

Is it possible to run a node.js CL app without using the global folder?

I would like to know whether it is possible somehow to run a node.js command line app without using the global folder, i.e. no npm install -g or npm link.
If you want to use a cli that is npm installed locally without using anything else, you can do (assuming webpack):
node ./node_modules/.bin/webpack
Just check that directory ./node_modules/.bin
Probably npx would work for you.
$ npm i -D webpack
$ npx webpack ...

Nodemon for development environment

I wanted to know how to use nodemon, and push it to a git repo, and have other developers on the project be able to use nodemon without having to run the command npm install -g nodemon. Ideally, I would like all developers on the project to be able to just run npm start and nodemon is called whether or not it's installed globally. I've already run npm install --save-dev nodemon, and I'm mostly curious if there is a way to get nodemon to be run from within node_modules, in my start command in the scripts section of the package.json file.
If you install it locally, i.e. without the -g flag, it's available in ./node_modules/.bin/nodemon. So just configure that path in your npm start script.
For example:
"start" : "./node_modules/.bin/nodemon app.js"

Resources