KeystoneJS setup placing files in wrong directory - node.js

So I run yo keystone after install keystone then run through all the setup instructions.
However, it always places it into my ~/ directory even when I add in the option to create a new directory. Thus, all the files conflict with other files in my ~/ directory.
How can I cd into a directory and install it without it placing them all into ~/

First of all, you need to cd into your directory:
mkdir myproject
cd myproject
yo keystone

Related

Why does npm install keep saving under node modules folder even though i changed directory to another folder?

In terminal, I entered the command cd /Users/MyUserName/Google/Google Drive/Coding then entered the command npm install underscore. So I figured the underscore module would be saved under my Coding folder; however, it keeps saving under the directory: /Users/MyUserName/node_modules/
How do I change the setting so that when ever I change my directory in terminal and enter a npm install command, the module gets installed in the respective changed directory?
From the 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.
So it seems the package is installed under your home folder because it already contains a node_modules folder. If you remove that the install should go into the current folder.
Alternatively: Add a node_modules folder to the current folder.

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.

npm package.json and docker (mounting it...)

I am using Docker, so this case might look weird. But I want my whole /data directory to be mounted inside my docker container when developing.
My /data folder container my package.json file, an app directory and a bunch of other stuff.
The problem is that I want my node_modules folder to NOT be persistent, only the package.json file.
I have tried a couple of things, but package.json and npm is giving me a hard time here...
Mounting the package.json file directly will break npm. npm tries to rename the file on save, which is not possible when its a mounted file.
Mounting the parent folder (/data) will mount the node_modules folder.
I cant find any configuration option to put node_modules in another folder outside /data, example /dist
Putting package.json in /data/conf mounting the /data/conf as a volume instead wont work. I cant find any way to specify the package.json path in npmrc.
Putting package.json in /data/conf and symlinking it to /data/package.json wont work. npm breaks the symlink and replaces it with a file.
Copying data back and forth to/from inside the docker container is how I am doing it now.. A little tedious.. I also want a clean solution..
As you have already answered, I think that might be the only solution right now.
When you are building your Docker image, do something like:
COPY data/package.json /data/
RUN mkdir /dist/node_modules && ln -s /dist/node_modules /data/node_modules && cd /data && npm install
And for other stuff (like bower, do the same thing)
COPY data/.bowerrc /data/
COPY data/bower.json /data/
RUN mkdir /dist/vendor && ln -s /dist/vendor /data/vendor && cd /data && bower install --allow-root
And COPY data/ /data at the end (so you are able to use Dockers caching and not having to do npm/docker installation when there is a change to data.
You will also need to create the symlinks you need and store them in your git-repo. They will be invalid on the outside, but will happely work on the inside of your container.
Using this solution, you are able to mount your $PWD/data:/data without getting the npm/bower "junk" outside your container. And you will still be able to build your image as a standalone deployment of your service..
A similar and alternative way is to use NODE_ENV variable instead of creating a symlink.
RUN mkdir -p /dist/node_modules
RUN cp -r node_modules/* /dist/node_modules/
ENV NODE_PATH /dist/node_modules
Here you first create a new directory for node_modules, copy all modules there, and have Node read the modules from there.
I've been having this problem for some time now, and the accepted solution didn't work for me*
I found this link, which had an edit pointing here and this indeed worked for me:
volumes:
- ./:/data
- /data/node_modules
In this case the Engine creates a volume (see Compose reference on volumes) which is not mounted to your source directory. This was the easiest solution and didn't require me to do any symlinking, setting paths, etc.
For reference, my simple Dockerfile just looks like this:
# install node requirements
WORKDIR /data
COPY ./package.json ./package.json
RUN npm install -qq
# add source code
COPY ./ ./
# run watch script
CMD npm run watch
(The watch script is just webpack --watch -d)
Hope this is able to help someone and save hours of time like it did for me!
'*' = I couldn't get webpack to work from my package.json scripts and installing anything while inside the container created the node_modules folder with whatever I just installed (I run npm i --save [packages] from inside the container to get the package update the package.json until the next rebuild)
The solution I went with was placing the node_modules folder in /dist/node_modules, and making a symlink to it from /data/node_modules. I can do this both in my Dockerfile so it will use it when building, and I can submit my symlinks to my git-repo. Everything worked out nicely..
Maybe you can save your container, and then rebuild it regularly with a minimal dockerfile
FROM my_container
and a .dockerignore file containing
/data/node_modules
See the doc
http://docs.docker.com/reference/builder/#the-dockerignore-file

Install Stylus manually from .zip file

i have a problem installing stylus through npm install because of the proxy settings of my network. I want to know how to install stylus manually with the .zip file that i just downloaded from their github.
Well, you should put all content of this archive in $NODE_PATH/stylus folder:
cd $NODE_PATH
mkdir stylus
cd stylus
<copy all here>
Then you should symlink bin/stylus from this folder to some dir in your PATH variable, for example /usr/local/bin/ (if you on Linux or OS X):
ln -s bin/stylus /usr/local/bin/stylus
That's all.
P.S.: You can configure npm to use proxy. See http://jjasonclark.com/how-to-setup-node-behind-web-proxy for detail information.

What is the npm tmp directory? Can I delete it?

On a brand new Ubuntu machine 12.04.3 I did the following installations on my home directory:
Git: sudo apt-get install git
Node.js: sudo apt-get install nodejs and updated it with sudo npm cache clean -f, sudo npm install -g n, sudo n stable
npm: sudo apt-get install npm and then updated it with npm update npm -g
Yoeman: sudo npm install -g yo
A new "tmp" directory popped up in my home directory with the following structure:
npm-13728-uErqEQ4O:
1392566713336-0.9297236264683306 1392566726706-0.4921755278483033
npm-13763-yoMEDYdC:
1392566864990-0.09957328205928206
Each of the uErqEQ4O subdirectories contain:
tmp.tgz
package:
AUTHORS configure html make.bat node_modules scripts
bin CONTRIBUTING.md lib Makefile package.json test
cli.js doc LICENSE man README.md
The yoMEDYdC subdirectory contains:
tmp.tgz
package:
cli.js package.json readme.md scripts yeoman.txt yoyo.js
What is this tmp npm directory and everything inside it? Why was it generated?
Can I delete it? If not, where can I move it to because I don't want it in my home directory?
Tmp or temp generally means some kind of temporary storage, which is auto generated by program (mostly per one session):
Here is what the npm tmp directory is:
Temporary files are stored by default in the folder specified by the
tmp config, which defaults to the TMPDIR, TMP, or TEMP environment
variables, or /tmp on Unix and c:\windows\temp on Windows.
Temp files are given a unique folder under this root for each run of
the program, and are deleted upon successful exit.
If you are not sure can you delete it, just add some prefix to it e.g. _tmp and try to run you app. If it runs with prefix then you can delete it. If not, then you app has some kind of reference to it.

Resources