Can't load module in Node console using symlinks - node.js

I'm on cygwin to do unix commands on win7 (launched cygwin.bat in windows cmd prompt).
My project directories are created in root like this:
$ mkdir -p app/models
$ mkdir -p app/node_modules
Then the symlink is created:
$ cd app/node_modules
$ ln -sf ../models
Back on the /app/ directory, I go into Node console to launch the module located in
app/models/movie.js:
Movie = require('models/movie');
But I get the following error:
Cannot find module 'models/movie'

ln takes 2 arguments, not one.

I found out that cygwin doesn't really create actual symlinks by default. I had to create native NTFS symlinks using export CYGWIN="winsymlinks:native"

Related

Installing package Golearn

I'm try to install the package Golearn, following these instructions.
After running in the terminal
go get -t -u -v github.com/sjwhitworth/golearn
I tried to run (as required):
cd $GOPATH/src/github.com/sjwhitworth/golearn
However bash doesn't find this directory. What should I do?
(I'm using linux)
install the package Golearn
Example build, in /home/name/tmp/
git clone https://github.com/sjwhitworth/golearn.git
cd golearn/
## Completing the installation
## Run the following to complete installation
go get -t -u -v ./...
Using : Please (also) read the text file README.md .
I did the following and worked:
go get -t -u -v github.com/sjwhitworth/golearn
go: downloading github.com/sjwhitworth/golearn v0.0.0-20221228163002-74ae077eafb2
go: added github.com/sjwhitworth/golearn v0.0.0-20221228163002-74ae077eafb
go env GOPATH
/Users/<my_username>/go
cd /Users/<my_username>/go/pkg/mod/github.com/sjwhitworth/golearn#v0.0.0-20221228163002-74ae077eafb2
sudo go get -t -u -v ./...
The instruction of golearn maybe some outdated, you can follow my process:
cd into a empty folder, like /home/your/code/my_golearn, all commands below should be run at this floder
run go mod init my_golearn to init a go project, you will get a go.mod file
create a main.go file and fill it with code from https://github.com/sjwhitworth/golearn#getting-started
run go get github.com/sjwhitworth/golearn
run go mod download to get all dependencies
run go get github.com/sjwhitworth/golearn/knn, it's strange, but it doesn't work if this command miss, I think maybe the developer of golearn has some misuse of go mod
run wget https://raw.githubusercontent.com/sjwhitworth/golearn/master/examples/datasets/iris.csv -P datasets to get dataset you need
run go run ./main.go, you will get result same as https://github.com/sjwhitworth/golearn#getting-started
If you are not familiar with how to install dependency in a modern go project, it's better for you to go through https://go.dev/blog/using-go-modules

KeystoneJS setup placing files in wrong directory

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

How to make offline installation of node-inspector?

How to offline install node-inspector on Windows server?
The code is here: https://github.com/node-inspector/node-inspector
https://www.npmjs.com/package/node-inspector
To my best knowledge, it's not possible to install Node Inspector (or any npmjs package) directly from npmjs.org and/or github.com without a working internet connection. However, you can prepare a self-containing package on a machine that does have internet connection, and then install this package on an offline host.
Here are the instructions, assuming Unix system.
On the machine connected to the internet
$ mkdir tempdir && cd tempdir
$ npm init # fill any data to prompts
$ npm install node-inspector
$ cd node_modules/node-inspector
$ tar czf ../../node-inspector.tgz .
$ cd ../..
Copy node-inspector.tgz to the offline machine and unpack it in the directory of your choice, e.g. $HOME/node-inspector or /usr/local/lib/node_modules/node-inspector
Create symlinks for node-inspector and node-debug in a folder that is in your PATH. For example:
$ cd /usr/local/bin
$ ln -s ../lib/node_modules/node-inspector/bin/node-inspector .
$ ln -s ../lib/node_modules/node-inspector/bin/node-debug .

Using SUDO with NVM?

How is it to execute something like sudo npm rebuild or sudo node if Node.js was installed by NVM ?
Each time I type sudo command, my console tries to execute npm or node program in /usr/bin/ or /usr/lib, neither of which do exist.
Try creating symlinks in /usr/bin or /usr/lib. Not a strong solution, but may be enough.
sudo ln -s /home/denny/.nvm/versions/node/v0.12.0/bin/npm /usr/bin/npm
sudo for writing in system location. Suggestions here may happen useful, especially rvmsudo or group access.
Other suggestion:
According to comment, you may try to create a bash script at /home/denny/npm.sh:
#!/bin/bash
PTH="/home/denny/.nvm/versions/node/$(node -v)/bin/npm"
$PTH
chmode it +x properly and create symlink with this:
sudo ln -s /home/denny/npm.sh /usr/bin/npm
Should always check for node -v and run npm from proper directory.
I needed to do this to run the Atom installation script, but I didn't want to permanently change my machine setup. So, I did:
sudo bash
and then I sourced the nvm.sh file in my user's home directory tree:
source /home/ada-lovelace/.nvm/nvm.sh
That let me run the necessary commands with root. Of course, this means the very next time I need to run node in a session with root I'll have to do these steps again, but I don't anticipate needing to do this in the near future.

Makefile install copy executable to usr/local/bin Linux

In my Makefile I'm trying to copy the executable file into usr/local/bin.
install:
sudo cp program1 usr/local/bin
My Makefile and program1-file is in a directory src in Documents so this doesn't work. I probably need the whole path from my src directory.
Is there a general way to make it work regardless of where I put my directory with the Makefile and executable? Maybe using the PATH variable or something?
usr/local/bin is a relative path. If you don't want that, use an absolute path:
install:
cp whatever /usr/local/bin
Some tips:
Don't use sudo in your Makefile, that's unusual. Note in the installation docs that the install target has to be run by a user with sufficient privileges (and people will do sudo make install when they want to)
Look into the install (man install), it's meant for this sort of thing.

Resources