How to configure node_modules folder location in npm project? - node.js

I have a node application in which I am using package.json file which on npm install make a node_modules folder inside the application folder which have all dependencies in it. I want to move node_modules folder out from application folder without causing the code break. Basically I want to manually configure the location of local node modules. How can I do that?

Related

How to deploy local node_modules folder onto heroku

I have done some changes inside node_modules folder inside a module and run NPM install again inside a module in node_modules. It's working fine on local.
Now, I want to deploy it on Heroku. But Heroku looks at the package.json file and installs all the NPM modules again.
So, Please let me know "How can I deploy local node_modules folder onto Heroku" and prevent Heroku to NPM install again.

implementing monorepo for react and node js web application using lerna

i am trying to build a monorepo , which consist of a react and node js application so the frontEnd folder which is created using react app and backEnd folder which consist of all server code.
I have done the below steps
installed lerna globally
created a new folder and initialized the repository.
inside the new folder run lerna init, which created 2 files lerna.json, package.json and 1 folder as packages.
inside packages folder i run create-react-app frontEnd, it created a new react application
run the command mkdir backEnd, to created the backEnd folder in the packages folder
now my packages folder consist of two folders frontEnd and backEnd.
the frontEnd consist of a package.json which comes with create-react-app
questions
Do i need to remove the package.json from the frontEnd folder
how i configure the lerna.json and package.json in the root folder.
how can i run the application?
i have searched but i am not getting the solution to make a react-nodejs application with lerna using create-react-app
I did this task here
Do i need to remove the package.json from the frontEnd folder
No, each project in the /packages folder may have its dependencies. The modules installed in the root package.json are installed in all the subproject. When you run lerna bootstrap it will run npm install on each project.
how i configure the lerna.json and package.json in the root folder.
The lerna.json is quite simple and contains configuration that collects all the project lerna should manage.
The package.json is to track shared packages between all your project. For example you could have some constant-module that must be the same version on both the projects.
In a simple fontend/backend, it is realistic to don't have any shared modules.
how can i run the application?
when you run lerna run start, lerna will execute npm run start on all the tracked project. So you must be aware how to start you whole application.
In my example, I implemented the start only in the backend project since it will serve statically the frontend files and I didn't want to start another webserver only for the frontend.

unable to install npm packages in created folder - ubuntu

The system I am using is Ubuntu 17.
I cloned a repository from github in the bundler-app folder.
I created a folder packages in it using mkdir packages/myfolder.
Now, I go to the myfolder folder and do yarn add react react-dom
and the install happens. Everything seems to go smoothly and yet
when I go to the myfolder folder and see what's in there... it's empty.
There's nothing in it.
So, where did the yarn/npm packages go?
Does one of the parent folders of myfolder contains a package.json, if so yarn adds the package there.
If you need different behaviour to install under the current folder, even if a parent folder has package.json, you will have to make sure current folder has a package.json, which can be done via yarn init.
So in your case you can try
yarn init then yarn add react react-dom inside the folder and you will find the package in the folder

npm install local folder only installs node_modules

I want to install a local project by using "file:../project-name" in the package.json. However, when I run this command it only installs the dependencies of the local project (node_modules) and not the source files itself.
I have project-name/src for example and I expect it to appear in node_modules/project-name/src, but it doesn't.
I checked the .gitignore (I don't have a .npmignore file) and src as a folder is not excluded.
What am I not seeing here?
If you refer to the files property, this does not indicate files to copy to the node_modules on npm install, but it indicates the files to publish on npm publish.
Edit
When including a dependency with file:... in a project, the directory has to:
have a package.json
Declare exported files in the "files" property.

npm not creating node_modules folder in project directory

I am doing a small Sinatra project and I want to use Gulp.
I have node(v0.12.0), npm(2.13.1), gulp(3.9.0) installed. I am in my project directory but when I try install a package like "npm install gulp-sass --save-dev", it doesn't create any "node_modules" folder in my project directory. It seems to be installing the package in my user home directory. Anything I am doing wrong?
From the npm documentation:
Starting at the $PWD, npm will walk up the folder tree checking for a folder that contains either a package.json file, or a node_modules folder. If such a thing is found, then that is treated as the effective "current directory" for the purpose of running npm commands. (This behavior is inspired by and similar to git's .git-folder seeking logic when running git commands in a working dir.)
If no package root is found, then the current folder is used.

Resources