I did a node console script for some internal task using some dependences and it is working well. Now I have two questions:
1) how to install it globally on my computer?
I need to launch the script like this:
node myscript.js PARAM1
And, how I´ve said, it works ok. The fact is that now I want to "install" my script globally. How to do that? I´m mac user and I know that I can create an alias like this:
alias myexec='node myscript.js'
then I could use it like this:
myexec PARAM1
is this the correct way to do it? is there any other alternative maybe?
2) How to distribute?
I have some computers on my company where I need to install it (Windows & Mac), I can clone the repo and do the alias thing... is this my best option?
Thanks in advance
Related
I have no admin rights in my windows machine. Can I install NVM without admin rights? I tried using the environment variable path setup, but its not working in my case.
I have the same need and couldn't find one, so I created one base on another simple nvm:
https://www.npmjs.com/package/#jchip/nvm
Requires powershell 4+ and permission to execute scripts.
(You're talking about https://github.com/coreybutler/nvm-windows right?)
Whether you can install it without admin rights aside, the actual act of switching node versions with it requires them so you're going to have trouble.
Your best bet is to install different versions of node into different paths manually, and then configure your environment variables to point to the right one whenever you need to use it.
eg. prefix your cmd script with PATH=C:\node\v10;%PATH% to have any node or npm calls in that script use whatever node is sitting in v10
try this
create a bat file like below
#cd C:\Users\testuser\AppData\Roaming\nvm
#SET PATH=C:\Users\testuser\AppData\Roaming\nvm\v14.21.1;%PATH%
cd c:\users\testuser\Desktop\Project
#cmd.exe /K
Run bat file and type
code .
It's open with VSCode
go to the terminal and type node and you can see the node version that you set in the bat file.
enter image description here
You can apply any node version as above bat file
If you use Git Bash on Windows, you can add this to your bash.bashrc to switch node versions:
export PATH=/c/path/to/node/dir:$PATH
Then just restart your terminal to pick up the updated PATH.
It will prepend your path with your desired node version. It's the only way I've found to override the installed node version if you don't have admin rights on your machine.
I want to create a custom command in node.js, like create-react-app please share me the details,if i run that command in node terminal it should create some directroy and files like create-react-app dose
so that i can run that command like this
->cutsom_command myapp
If you want to kickstart a new projects with the same set of packages, try using Yeoman. It will be much easier to use it instead of writing your utility from ground up.
I am trying to integrate Hubot with rocketchat and make Hubot talk with rocketchat.
The sources I am referring to are:
https://hubot.github.com/docs/
https://github.com/RocketChat/hubot-rocketchat
I have installed Nodejs and in Node.js command prompt I did:
mkdir myhubot
cd myhubot
yo hubot
Questions I have:
How do I understand if rocketchat is integrated with Hubot?
If I have not integrated rocketchat, how should I do it? (I did refer to https://github.com/RocketChat/hubot-rocketchat). Here, I want to understand how and where to set environment variables. Also, how exactly do I run Docker here?
When I do docker export ROCKETCHAT_ROOM='https: //spree.chat/channel/'
It returns: "Cowardly refusing to save to a terminal. Use the -o flag or redirect."
How can I resolve this?
Here is the screenshot:
1.) Rocket.chat have "Internal hubot" which is integraded and contain some simplest Hubot scripts. Ideal for testing and introduction to Hubot. You can find these scripts in rocketchat/programs/server/npm/node_modules/meteor/rocketchat_internal-hubot/node_modules/hubot-scripts/src/scripts/.
If you wanna use more complex scripts, you must use external Hubot.
2.) Setup "Environment Variables" are different for each platform. For example, if you want set ROCKETCHAT_ROOM to support, you must use something like env ROCKETCHAT_ROOM=support. But this only applies to Linux OS. For Docker syntax is -e ROCKETCHAT_ROOM=support. If you running external Hubot on Windows, you probably must use something different.
3.) ROCKETCHAT_ROOM variable is not for URL of your channel. You must put here name of your chat room.
Before I start, I want to say that I already checked these answers:
Jenkins build step fails on 'npm install <whatever>'
Jenkin's build failing on npm install
Now, I'm dealing with this issue for a while already and thus I tried a bunch of stuff.
Firstly, I installed node + npm via homebrew. A simple $ node -v and $ npm -v echoed the version v0.10.36 for node and v2.3.* for npm, which also means I HAVE THEM IN THE PATH and they work while called in the terminal.
Simply adding node -v; npm -v to the execute shell in Jenkins didn't do it. After a bit of tinkering I copied what $: which node yielded in the terminal to the above mentioned script, which now looked like this: /usr/local/bin/node and apparently that worked. The Jenkins build succeeded and 'node-v0.10.36' was proudly displayed in the console output.
When doing the same for 'npm' which happened to be /usr/local/bin/npm --version the computing gods weren't so merciful anymore. A big 'env: node: No such file or directory' error was thrown this time and the whole build failed.
The actual command that fails is
$ /bin/sh -xe /var/folders/wr/g_dl81tn5_x0t_yz3jw602cr0000gn/T/hudson8770480548136671253.sh and "surprisingly" when I run the same command in the terminal it succeeds.
I also uninstalled the homebrew node & npm versions and installed them afterwards via the package manager. Same results.
Ultimately I also did this: https://gist.github.com/DanHerbert/9520689, with no luck.
Notes:
I'm running Jenkins 1.613 and tried with 1.5**
I didn't create a "Jenkins" specific user but instead I'm using the admin. This happens to be the same user that Jenkins runs, since the who am i command inside the executable script yields the admin's user name.
sudo'ing doens't help
I'm also running the whole thing in a Virtual Environment - vagrant
I'm not running Jenkins as a deamon, as it's conflicting with xtools, but as a simple process
I also tried out jenkins-node plugin with various configs (can detail if needed)
Thanks a lot for your help, and let me know if you need any other info, screenshots, logs, etc.
I found my own solution. The problem was that the PATH although visible in shell was not exported for the Jenkins job, and so, the first workaround, as found here, was to export it in the actual script like so:
but this feels like a hack!
The right and elegant solution is to use Jenkins EnvInject Plugin and export the path in the added Properties content textarea on the configuration page, like so:
Manage Jenkins -> Configure System -> Global properties -> Environment variables
My company has locked down access to CMD.EXE (not sure why)..
I am futtzing around with Node.JS, installed it via the official Windows installer but found I have 0 access to cmd.exe and now I am wondering if I can even go about learning it with the Node terminal only?
Simple things like node -v do not work in the terminal. You have to actually do process.version.
I want to install express as another example and it does not work either.
npm install -g express-generator
Is there another keyword to use in place of npm when using Node.js Terminal?
Also when the Node.js terminal stops at ... is Ctrl-D the only option to break?
They allow you to run installers, but block access to cmd.exe? That is odd, but there are some more options.
Have you tried Powershell? If cmd.exe is blocked, they might have also blocked Powershell.
Install a third party console. Something like:
console
ConEmu
PowerCmd
Use an IDE with built in support like WebMatrix
Install Node on a remote server that you can SSH into (using Putty or similar tools).
Free AWS Micro Instance
$150 / month free on Azure if you can qualify as a startup.
Cheap hosting with Digital Ocean
Free VPS with 5Jelly (Never used them, can't vouch for quality)
Ask your tech department for access (should probably be #1 :)
When you just double-click on or execute just "node.exe" at a command prompt, you get the REPL, which is an environment that allows you to execute javascript code. It's not a regular command prompt.