I want to create a new macro command in JS for my project and I heard about sweet.js.
After I was reading about that a little bit I found this page that explain how to export your commands, but I didn't really understand the Github system and I always see commands with syntax like that: $ sjs --module ./macros.js my_sweet_code.js and I can't figure out where I'm supposed to run those commands. So if someone can explain how to use this library and how to run github commands in general I will be glad.
P.S: I saw sweet.js is a mozilla library, it means that it works only on FF? Ff yes, is there any solution for all the browsers?
The line sjs --module ./macros.js my_sweet_code.js needs to be run on the command line on a system that has node.js and sweet.js installed. You can install node from here and once that's installed you can use the npm command on the command line to installed sweet.js: npm install -g sweet.js. With sweet.js installed you can then use the sjs command to compile code.
Also, sweet.js is a Mozilla project it but works everywhere.
Related
I have a usable workflow that I want to make better. I'm building a JS library, and the way I am executing smoke tests on code is by using webpack to package the library and write it to a file that is included in an HTML file for viewing the effects of the code.
To do this, I make changes to the file in Eclipse, save it, then I must leave Leave eclipse and go to Terminal to run "npm run buildInbrowser" to execute "webpack --config inbrowser.config.js".
The configuration works perfect with regards to webpack, the configuration, and the npm setup, but when I try to configure eclipse to run those commands, it brings up an error: "env: node: No such file or directory" I've attached screenshots of my launch NPM configuration.
My system is MacOSX Catalina using Nodeclipse, npm v9.3.1 and node 16.18.0.
Again, there is no issue with me running these commands in terminal, but they won't run through node. This makes me think it's something simple that I overlooked.
As nitind pointed out, I had incorrect syntax on the PATH variable for eclipse, which was causing the problem. Also noted is that Eclipse did not populate my path variable by default, so i did have to manually enter it in. See the screen shot for the fix.
When using npx tsc --init without typescript installed, NPM seems to go through the motions to download tsc, and has some commands, but not all (it doesn't have --init), and I realize its because its using a really old version of tsc. Thats annoying, it should use the latest one :)
To reproduce this yourself, make sure you don't have typescript installed globally and also are not in a NPM project (with package.json). Then type npx tsc --version: you will get
npx: installed 1 in 0.868s
message TS6029: Version 1.5.3
Obviously the workaround is to install typescript first, but then there is no point of npx, is there? Only then do I get the latest version:
Version 4.1.3
As Estus Flask said in his answer here, when you use tsc without typescript installed, you are using the deprecated tsc package, which I personally wasn't able to find using https://www.npmjs.com/search?q=tsc probably because it has fallen way down in the search ranking.
His answer has more detail and tips to make npx still work without installing typescript: npx -p typescript tsc (-p means "Package to be installed.")
After typing the question, it looks like a similar question has been asked before. But this question has got nothing to do with virtual machines (the original question): "npx tsc --version" reports different TypeScript version inside virtual machine
I am using Visual Studio Code (VSC) 0.10.11 on Windows and Mac. For the purpose of this question I have this small JavaScript snippet:
'use strict';
const os = require('os');
console.log(os.homedir());
I followed John Papa on Visual Studio Code (Blog entry and Pluralsight Visual Studio Code JavaScript Intellisense - for those who have an account) and therefore I would expect that VSC provides Intellisense and Quick fix options when typings are available.
In the snippet above VSC recognizes console and log() (I use hoover, but it is the same with Intellisense):
but not os and homedir():
But all 4 typings are available in typings/main/ambient/node/index.d.ts. I know that the difference is the require in the case of os, but in John Papa's video course VSC also provided IntelliSense for required modules. A difference is that John Papa used tsd while I am using typings.
So my questions are
how can I enable Intellisense for all known typings?
what do I have to do that VSC offers me Quick fix (green line under moduls with missing typings)?
The above links are outdated. In older versions of VS Code you needed to reference your typings like /// <reference path> for somelibrary.d.ts.
With new version you need to initialize your project by creating jsconfig.json at the root of your project and add the following inside:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs"
},
"exclude": [
"node_modules"
]
}
Next install typing you need. You can use either tsd or typings. In your case you need to install tsd install node or typings install node --ambient. Make sure you have typings/tsd installed. Restart project.
Please refer to docs:
Setup JS project - https://code.visualstudio.com/docs/languages/javascript
Node.js - https://code.visualstudio.com/docs/runtimes/nodejs
Debugging - https://code.visualstudio.com/docs/editor/debugging
Update:
Since version 1.7 there is no need to manually install typings, they should be downloaded automatically. Better JavaScript IntelliSense
There is a built-in extension called TypeScript and JavaScript Language Features (vscode.typescript-language-features) that is disabled.
In order to enable it, open Extensions panel, search for "#built-in JavaScript", and enable the required extension.
Now you should be able to use the autocomplete feature.
I experienced this on global "process" object. Vscode enabled intellisense for process object, only if I add any "require" statements to the file.
So if there is not any other require statements, you can add
const process = require('process');
in the beginning of your script to get intellisense.
Well, after 4 hr's googling finally, I decided to uninstall nodejs, npm, and typescript then install all of them again. The previous time I installed them using nvm but this time I decided not to use nvm just install them from node source since I am using Ubuntu I executed bellow commands, for windows or mac just install them without any package or version manager.
curl https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb https://deb.nodesource.com/node_7.x $(lsb_release -sc) main"
sudo apt-get update
sudo apt-get install nodejs
above command installed both nodejs and npm, after then to install typescript I ran bellow command
sudo npm install --global typescript
I updated my VSCode to the newest version.
Then in the bottom right of my VSCode I clicked on javascript to change the language mode, I wrote 'type' on the search bar and select typescript as my new selected language mode...........BINGO
Forgive me if this is a daft question but I'm utterly baffled as to how I can use JSDoc on Windows. I'm aware of JSDoc-Toolkit but it's a bit out of date and the google code repository recommends to use JSDoc 3 instead. I have downloaded JSDoc from Github and unzipped the jsdoc-master folder onto my local disk but can't find any solid information as to how to use it to parse my files.
You can download it as an npm package for the Node.js JavaScript runtime environment.
Install Node.js which comes with npm
Open your a command line
Install JsDoc by typing the following command
npm install -g jsdoc
Run JsDoc / generate documentation. more info
jsdoc path/to/file.js
Configure jsdoc (Optional)
The installation is not good documented on the project-page.
It is much better exlained on the github-page.
I don't know very much about NodeJS/npm ecosystem. However, I did the following steps below and it worked for me (on windows):
Downloaded NodeJS zip file and extracted, it made a directory 'node-v16.15.1-win-x64' with node.exe and and npm.cmd inside
Executed command 'npm install -g jsdoc', under the 'node_modules' directory under the 'node-v16.15.1-win-x64' it installed the jsdoc (in a folder) and also made the jsdoc.cmd file inside 'node-v16.15.1-win-x64'.
This jsdoc.cmd works with the full path but it does not work without the full path
jsdoc gets installed and is working with the above steps but to access it from any where without giving the full path, I had to set the 'node-v16.15.1-win-x64' on Windows PATH, that works.
I am not sure if question of OP is answered but JSDoc works for me this way.
I'm not saying this is necessarily the best way, but it worked for me:
Install node.js
Open a command prompt
As a test, create a folder in your root drive (c:\test) and go to it (cd\test). I guess there was some sort of permission issue as I couldn't get the following steps to work in my desktop folder.
Install the JSDoc package: npm install jsdoc
There should be a folder in test called node_modules
Go to the .bin subfolder in node_modules
There should be a file called jsdoc.cmd. Simple use jsdoc myfile.js in the command prompt to execute the JSDoc script on your file
My NodeJs is working fine but i have an issue I'm not seeing $ in the prompt as most example point.
Another issue is when i put sudo I dont get anything.Things I have tried are the following
$ sudo npm install npm -g
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
npm#2.7.1 /usr/lib/node_modules/npm
given on the following Website
http://www.tutorialspoint.com/nodejs/nodejs_npm.htm
Apologies am very new to Node.JS.Please help
I'm going to explain this in terms familiar to MS windows.
$ npm --version
^ dollar sign is the same as "C:\" in windows.
It just means "from here..." in the most basic terms I can use.
You don't need the dollar sign for anything in that tutorial.
"sudo" means "elevate to an administrator level" similar to opening a command line terminal "in administrator mode." But for Linux (Ubuntu and Mac as *NIX) systems.
--version can be called as "-v" most of the time and means "for the thing I've named before, in this case "npm" show me the version.
Once you've installed NodeJS it comes with a "package manager" called NPM. The best way to relate this to windows is by considering it a command line version of an "installation" that installs different programs as you tell it to with different options.
"npm install -g" means "Hey NPM! Install to EVERYWHERE(call from command line/terminal/bash) the thing I Tell you next. "npm install -g express" for example, means hey NPM, install "expressJS" globally, so I can use the terminal to write commands(micro apps) from the expressJS I just installed with node.
"npm install --save" means hey, install this microapp, but ONLY let me use it in THIS EXACT FOLDER I'm in, and let anyone else that is in this folder know they need to install it to use this application I'm making.
"npm init" Is actually the FIRST thing you should do in any node project folder. It creates the "package.json" file in the current directory, and it will define the folder you're in as the folder to start installing stuff you "npm install" to the "node_modules" folder that will show in the folder you're currently in.
If you want to tinker with NodeJS code, and you don't want to tamper with your local machine and install all kinds of stuff you're not totally sure about yet you can use "REPL.it" (https://repl.it/languages/nodejs) the white window on the right is treated like a file you'd run in node. The dark window on the right is an actual NODE TERMINAL that you can run nodejs commands/code in directly.
There's one other good resources in general and that is here (https://devdocs.io/) it's called "Devdocs" and it has Node, npm, and express code examples, clean explanations, and examples that you can download directly to your local machine.
I hope that gets you moving with NodeJS. It's hard to understand, but with a bit of try and fail you'll start to try more and fail less. Cheers!