How do I use JSDoc on Windows? - javascript

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

Related

parcel-plugin-transcrypt fails with 'Error: Cannot find module 'parcel-bundler/src/Logger'

In a web project using yarn as package manager and parcel as bundler, I want to let Parcel transpile Transcrypt (Python) files to Javascript.
For this I installed parcel-plugin-transcrypt. But now when I bundle the project via parcel serve I get the following error:
Cannot find module 'parcel-bundler/src/Logger
Googling shows that this seems to be some version issue other plugins have encountered too. However I could not find a solution for parcel-plugin-transcrypt.
Any way to fix this?
The plugin for Transcrypt references files that have been refactored in newer versions of the bundler. To get it to work you need to add three missing files required by the build process. It's a work around for an underlying issue, but it fixes the problem for now. I use 3 wget commands to pull the files out of github and put them into the appropriate node_modules folder. So after installing parcel-bundler with npm, from the root folder of the project I run these:
wget -P ./node_modules/parcel-bundler/src/ https://raw.githubusercontent.com/parcel-bundler/parcel/b1e6d59cc44489f20013fa3171e09788978d7aed/packages/core/parcel-bundler/src/Logger.js
wget -P ./node_modules/parcel-bundler/src/utils/ https://raw.githubusercontent.com/parcel-bundler/parcel/b1e6d59cc44489f20013fa3171e09788978d7aed/packages/core/parcel-bundler/src/utils/prettyError.js
wget -P ./node_modules/parcel-bundler/src/utils/ https://raw.githubusercontent.com/parcel-bundler/parcel/b1e6d59cc44489f20013fa3171e09788978d7aed/packages/core/parcel-bundler/src/utils/emoji.js

how to use jsdoc in local project

Goal
I want to use jsdocs with npm.
Background
I am new to npm and its plugins. Recently I found out about jsdoc and I tried using it, with no success.
What I tried
First I installed the package using npm's command npm install --save jsdoc, and the install completed successfully.
However, when I try to use it in my project (I am inside the project's folder) I type jsdoc example.js and I get the following error:
/home/ubuntu/.nvm/versions/node/v4.4.5/bin/jsdoc: No such file or
directory
This leads me to think that:
I am in the wrong directory. If so, where should I be? (other than the project root folder)
The installation had a problem, even though it was successfull.
I have also tried to run npm jsdoc example.js but I get another error (this time from npm, saying I am not using it correctly).
I also installed jsdoc globally (using the -g flag) and it worked, but I truly want to avoid this because not all projects are using jsdoc.
Summary
To conclude, I am looking for a way to run jsdoc locally to a project with npm. Does anyone know of a way to do this?
To run jsdoc in the command line, the location of the jsdoc needs to be known. So when you have installed jsdoc globally, system would be able to find the file.
However if you want to run it locally, you need to include the file location before the jsdoc command.
For example, try using ./node_modules/jsdoc/jsdoc.js example.js

Node.js project with no package.json

Is it ok to have a node.js project with no package.json? The ones I see on the internet all come with package.json
What is the effect of having no package.json?
How is package.json created in the first place? Is it created automatically? I am wondering why I do not have package.json
Fundamentally, package.json is a meta file for your application. It lists all the configuration of your application.
What is the effect of having no package.json?
Nothing as far as you're running all your code locally and have no requirement for deployment whatsoever.
Let's setup a scene for you to understand this better.
Imagine that you wrote a brilliant application using node. Now all the chicks in your surrounding want it to play with. It is so fantastic!
Now you want to give it to them and during the development process you `npm install`ed so many things that your project grows beyond 4TB size.
There is no data storage device available to ship that huge code base.
Then the girl of your dream said I want it and I want it now. So you begin searching for app deployment process for node applications.
That is where you stumble upon a magical thing called package.json.
So what you do is you list all your npm installed modules under dependencies property. Then you delete node_modulesfolder, add package.json and commit the entire damn thing in github. Even the .zip file is of 10MB
Then she gets the code.
Types in npm install && npm start (which will install all the dependencies from the package.json` and start your application)
If you have package.json however, that is where you specify all your dependencies.
Using --save flag of npm install
Example.
npm install express --save
How is package.json created in the first place? Is it created automatically?
You can manually create a text file and save it as package.json
OR
A more sophisticated way is to use the command
npm init
I am wondering why I do not have package.json
Me too! :)
You're most probably following a tutorial that doesn't emphasize on initial configuration of the project OR the author of those tutorials presume that the reader has all the fundamentals down to begin with.
It is created automatically if you write npm init.
Then, every package you add using npm install packagename --save will be added to the dependencies list.
You need package.json so that when you want to use your project on another machine you don't have to copy all node_modules, but only your .js files you have written, assets and package.json. You can then run npm install command and it will automatically download and install all the required modules (found in the list of dependencies inside package.json).
You can also manually create or edit it, but it's easier to add --save when installing a module so you don't have to worry about package versions and stuff like that.
Also if you want to create a npm package, an open source project or stuff other people will use, it's either required or the norm to have this package.json file describing your project.
package.json is npm file, if you don't use npm you will not have this file, npm is a great tool if you want to use external libraries in your project but if you don't need it (which is very not likely unless you are doing something very simple), you don't need package.json file too.
To generate package.json file initialize npm in your project using npm init
possible reason thus it exist is you maybe you enter a wrong command like npm i -y, you must initialize the project first, just enter a command npm init -y
Welcome.
Well, if you are running it on your local machine, it's fine. now to answer your last question, package.json is not created automatically.
the npm command npm init -y creates the 'package.json' file. It basically makes sharing your code and installing your codebase easier.

Create file with command line in Node

So I'm attempting to do this Node.js tutorial, and it says to create three .js files from the command line.
touch server.js client.js test.js
Except I get the following error:
'touch' is not recognized as an internal or external command, operable
program or batch file.
Not sure what is wrong here. I've installed Node.js as well as npm and browserify. I've created the package.json file correctly.
I suppose I could go into the project directory, right click and make a new file that way, but that defeats the purpose doesn't it?
What is the actual command to create a new file in the command line?
I'm using Windows 7.
That command is for a unix environment. You can use the following to create an empty file with similar functionalities that touch has in windows:
echo $null >> server.js in the desired directory
You can use the following command:
echo> index.js
touch is generally present on *nix platforms but not Windows. You will be able to follow the tutorial without it.
The tutorial author is using it to create empty files. You could achieve the same by simply saving files with the same names using an editor.
Alternatively, if you really want to use it in Windows, try Cygwin.
I know this is an old post, but the question is still relevant and there is a way to integrate the touch command into Windows, using the touch-for-windows npm package. It can be installed globally via node/npm with npm install -g touch-for-windows.
As someone who uses a pretty customized terminal across multiple machines, Cygwin didn't provide some of the other features I often use. The echo command (and accepted answer) provided by ltalhouarne works, but I felt was cumbersome to use. This npm package, though old, operates exactly in Windows as the touch command in *nix.
You can use :
copy nul > Gulpfile.js
You can also use the following command:
copy con [filename.extension]
[Note: Don't include square brackets]
That's it!
Follow the link
For installation in Windows
https://www.npmjs.com/package/touch-for-windows
Installation
In command prompt type:
npm install -g touch-for-windows.
Usage
After installing, you can run this application via the command line, as shown below.
C:\pythonapp>touch index.html
Successfully created 'index.html'
Worked for me
cd > filename.txt works too... if u create txt files, then it will have the file path on them. Just remember to delete them.
If you want a cross-platform solution in an environment where you have Node.js installed, you can as well run javascript code with node:
node -e "require('fs').writeFileSync('server.js', '')"
node -e "require('fs').writeFileSync('client.js', '')"
node -e "require('fs').writeFileSync('test.js', '')"
The commands above will create your 3 files with no content. You can also replace the '' by any content you would like to have in the file.
For more complex logics, you can move your code into a javascript file and execute it like:
node path/to/script.js
If you use git, there is already a bash installed inside
c:\Program Files\Git\bin\bash.exe
You can use it to work without installing cygwin. It contains the touch command.
Use the below command example to create any file in cmd:
type NUL > index.js
(here index.js is the file I want to create)

Can't find Typescript compiler: Command "tsc" is not valid

Just installed Typescript extension to VS2012 and followed Install TypeScript for Visual Studio 2012 and then the tutorial to call the compiler:
> tsc greeter.ts
But when i try to compile .ts file where should i type: tsc greeter.ts? Tried it in VS command line and in windows console, always get the message that tsc is not recognized as command(Command "tsc" is not valid.).
If you're using tsc as a node module, make sure you've installed it with
npm install -g typescript
Then it should be available globally in your node command prompt
Ensure you have,
C:\Program Files (x86)\Microsoft SDKs\TypeScript\0.8.0.0
or,
C:\Program Files\Microsoft SDKs\TypeScript\0.8.0.0
on your path. If not, try restarting CMD.EXE and see if shows up with a fresh copy. If that fails, try adding one of the above manually to your path.
For folks on Windows with Visual Studio Code, who don't want to install full Visual Studio just for tsc.exe, I can suggest to simply download it from here: https://www.microsoft.com/en-us/download/details.aspx?id=48593.
This is a shame that this link is missing from the TypeScript download page.
Although the installer is called TypeScript for Visual Studio 2015, it works with Visual Studio Code as well.
After you downloaded and installed TypeScript, you should manually add its installation directory (C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.0\ in my case) to the %PATH% environment variable.
Open environment variables editor:
Win + S; e, n, v, i, r, o; click Edit environment variables for your account.
In the window opened find Path user variable (note that it is not named %PATH% here, but still this is it). You probably have some path set there already. You just have to type ;, append the TypeScript install location and add one more ; in the end.
Screenshot for your reference:
After this is done, open Command Prompt and type in tsc -v. If tsc.exe's version is getting displayed, you're done. For this to work, restart Command Prompt and VS Code after making the change to the %PATH%.
P.S. If you get "error TS5057: Cannot find a tsconfig.json file at the specified directory: '.'", just create tsconfig.json file in the document root (that's probably where your .ts files are) with simple contents: {}. This means "an empty JSON file <...>. This will be sufficient for most people." (source).
Usually closing and reopen the command prompt solves the issues.
Check both of these folders to find out what TypeScript version you have:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\
C:\Program Files\Microsoft SDKs\TypeScript\
Right-click the folder showing the version number then 'copy as path'.
Paste this into your system path (quick access - Windows key then type 'env'). Then open a new command prompt console as administrator and 'tsc' should work.
If you have installed typescript for a specific folder/project i.e. not globally,then you can should use tsc command with npx
e.g
npx tsc myfile.ts
npx is used to excute a package .
As new path variable, don't use the displayed tsc version number but the TypeScript Folder Name which is different.
Sample :
tsc -v display 2.4.1
but TypeScript directory is
C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.4
Just delete AppData\Roaming\npm\tsc.ps1 file and the issue will be fixed.
In my case, I did install typescript globally by using -g flag but tsc was not recognized.
It turns out that below directory was not included in path environment variable:
C:\Users\Jitendra\AppData\Roaming\npm
Adding this directory to path variable worked for me.
In CMD type where tsc if it doesn't show a path like this C:\Program Files (x86)\Microsoft SDKs\TypeScript\typescript version you installed\ it means your tsc is not running from here.You need to change the environment path manually by following #TranslucentCloud 's answer .
You should add the following path
C:\Users\<user>\AppData\Roaming\npm
to the PATH variable. Notice that you should change the to your windows user.
This will work like a charm. Cheers!!
Try
npx tsc greeter.ts
I was getting the same error until i tried this.

Categories

Resources