How to correctly install Node modules to subfolder? - node.js

What is the official method for causing the node_modules folder to be created in a subfolder? I am using Bower for client-side files and happily installing them under a "client" folder. It would be great to use NPM for server-side dependencies and follow the same pattern. For example:
MyApplication
client
bower_modules
server
node_modules
.bowerrc
package.json
server.js
According to the NPM documentation, it is acceptable to install node modules into a folder other than default location. Unfortunately, uses the --prefix option prevents the dependencies section of package.json from being populating... which leads me to believe this is not the proper way of doing this.

I would just do:
git mv package.json server # (or just mv if you aren't using git)
cd server
npm install

node_modules and package.json follows each other, so you would either have to move your package.json or move your node_modules to the root of your project.
You can still have your client and server folders, that is a good idea!
MyApplication
node_modules
express
socket.io
client
bower_components/jquery/jquery.js
client.js
server
server.js
.bowerrc
package.json
server.js

Related

React js Project not successfully install ,How do fix

Folder structure Here
I will create react js project but not successfully install.Check this img
My version:-
npm -v 8.6.0
node v16.14.2
It seems like it's detecting another package.json file, could you send your root folder (ReactJS) content, possibly it's detecting another package.json file. If it's the case create a different directory where the root has no project created in it. You can use --force attribute but that's dangerous and not recommended.
Try this:
cd /home/himal/Development
mkdir new_app
cd new_app
npx create-react-app my-app

How to run Jest tests with Node (express.js) backend and create-react-app as frontend

I have the following folder structure:
Clearly React is using Jest in "Client" node_modules. If i try to install Jest for server node_modules (one lvl up), i will get error from React, saying i have duplicate packages up in the tree. How should i run tests for server with Jest? How should i install Jest for server? Or should i? Or i can use the same Jest react uses in "Client" folder? If so, how? What is the command? Really appreciate your help.
2 separate dependency trees, avoiding duplicate packages up in the tree would look like following:
server
├──> node_modules
├──> index.js
└──> package.json
client
├──> node_modules
├──> index.js
└──> package.json
.gitignore
README.md
Solved by using npm link client/node_modules/jest from project root .

Nested node_modules folder disappears after packaging

I'm building a test Electron app where I clone an express server repo, with its own node_modules folder, into my Electron repo, also with its own node_modules folder. The contents of my app looks like this:
main.js (starts app and forks process from the express app's index.js)
node_modules
package.json
cloned-express-app
|
--node_modules
index.js
package.json
When I package my app for Mac with electron-builder (with or without asar enabled) the inner node_modules directory doesn't make it into the packaged app. Is there some magic that Electron is doing to eliminate that folder? Is there some way I can ensure that it gets in?
Here are the contents of my main.js and my package.json in case that helps.
This is caused by a bug in electron-builder that is present after version 20.15.0 and at least up to version 20.26.0. Install electron-builder#20.15.0 and this issue will be fixed.

How to configure node_modules folder location in npm project?

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?

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