Creating new file with Node.js and Express - command-line

I'm trying to learn how to use Node.js and its packages. I'm in my Command Prompt (I'm on Windows), changed directory to my project folder. Then I installed the Express package:
npm install express --save
The npm installed the Express package. Now, while I'm still in the directory, I'm trying to create a new file:
touch index.js
But the file isn't created and I'm getting the following message:
'touch' is not recognized as an internal or external command, operable program or batch file.
Why is that? What am I doing wrong?

touch is no Windows command.
In this answer, they suggest this as an equivalent:
echo $null >> filename

touch is a Unix command that creates an empty file (or updates its timestamp if it doesn't exist). It has nothing to do with Node specifically.
Most Unix distributions (including OSX) will have touch installed by default. So I suspect you're on a Windows machine....

Related

'raml2html' is not recognized though installed via npm i -g raml2html: Windows

I was trying to run raml2html to convert some contracts to HTML, this was working initially when first time I did the installation on my Windows machine but after some weeks when I tired running this again then this command stopped working. Not sure what happened.
What I again tired installing raml2html by running npm i -g raml2html but still its saying:
'raml2html' is not recognized as an internal or external command,
operable program or batch file.
I again tried uninstalling and reinstalling also but still the same issue.
Try to find where the installation is creating the command line script for Windows (a file ending .cmd). That can be found opening a Powershell terminal and using the where command. It usually is under the C:\Users\<YourUserName>\AppData\Roaming\npm\node_modules directory.

Swift on Ubuntu 20.04- Need to add a path every time

I am simply trying to install swift on linux
I have downloaded the files from swift.org, extracted .tar files and used export command to include the path after that when I use swift --version it correctly shows the version 5.3.3 but when I close the terminal and try to open the swift command terminal it says command not found.
What is happening here? I need to include the path every time I open the terminal.
The export command just adds the value to path for the current session. When you log out and in again, it will reset.
You need to add this to your shell resource file so that it gets added to the path every time you log in. The file you need to edit will be called .zshrc or .bash_profile or something similar. You should start by opening the command line on your computer and verifying what shell you are running by typing:
echo $SHELL
This will return something like /bin/ksh or /bin/bash or similar. Then do a little internet searching to find out what the resource file is called for that shell. Then edit your resource file to add the Swift path to your $PATH.

Mongodb database tool commands wont take effect

I want to use commands such as mongodump/mongorestore/mongoexport on my local windows computer and have therefor downloaded the .msi extension version of mongodb database tool and also executed the .msi so it could be installed.
But what do i do now to start using the commands. I cant find any documentaions of this. Is there something i have to configue?
When i execute a command like mongodump on my system command line i get the response:
'mongodump' is not recognized as an internal or external command, operable program or batch file.
Do i maybe have to execute the command from a certain dir location?
Look for the highlighted folder on your system. When you install the database tools this folder is created. Inside this folder there is a bin folder which contains all the commands you are looking for.
Once you find this folder then navigate to bin folder. And open a command prompt at that location. And try running the commands.
Alternatively:-
You can set PATH to bin folder and then you will be able to run the commands from anywhere.

ionic install fails on fsevents on Windows

I have tried to install ionic on Windows but installation has failed. What should I do?
I have tried more than 20 times but still I got the same problem.
Here I have attached the screenshot for this
Entered commands:
npm install -g cordova
npm install -g ionic
Note: this one windows server machine
My guess is that the NPM global path has not been added to your windows path.
These are the steps to try:
First verify that the command just installed can run. The output contains the full path to the command installed, just copy and paste it to the command line. In your case it might be something like this %APPDATA%\Roaming\npm\iconic -v
Lets assume that works. That means that the command was successfully installed and will run, now we need to add it to your PATH so you can run it from the command line.
Next, Press Windows key and type "path" and select "Edit environment variables for your account". From here. Add or append the path %APPDATA%\Roaming\npm to your PATH variable, and save the results.
Once it is on your PATH you can run it from any command shell window.
Next, start a new command shell (e.g., Windows+R, cmd, Enter) and then type the command iconic -v. Viola, it should work without requiring the full path to the script.
I'm doing most of this from memory so hopefully it's correct. But if it needs some tweeks, let me know and I'll update the answer.
For completness, this install didn't actually fail. The lines with fsevents are warnings. The fsevents package is only designed to work on Mac Unix so these warnings can be safely ignored.
As Suraj Rao mentioned, also see Nodejs cannot find installed module on Windows?.

Using Scrapy with Windows Powershell

I'm unable to use scrapy commands via the Windows Powershell however I can use it via python using execute from scrapy.cmdline.
When I type anything beginning with scrapy, the 'open with' dialogue window pops up asking which program I'd like to use to open the file 'scrapy', which contains the following:
#!C:\Users\User\AppData\Local\Enthought\Canopy32\User\Scripts\python.exe
from scrapy.cmdline import execute
execute()
I've tried:
adding a . ahead of scrapy as suggested here
adding python ahead of commands suggested here
all of the above in cmd instead of PS
When I use scrapy through the Python interpreter everything functions correctly, does anybody have any suggestions as to what I'm doing wrong? Thanks.
I'm using PS version 2.0, Python 2.7.6 on Windows 7.
I'm guessing you have c:\Python27\Scripts\ folder in your PATH environment variable ($env:PATH to find out) - depends on your Python version, of course, it may be in that Enthought Canopy folder path, for instance.
When you type scrapy, Windows is finding the scrapy file (which you don't know exists, and that's why you say "there aren't any files") and trying to run it, but can't because it has no extension.
You are prompted to open it in a program, and you choose a text editor, and see the content (because there is a file). Instead you could choose to open it with Python - e.g. browsing to the C:\Users\User\AppData\Local\Enthought\Canopy32\User\Scripts\python.exe file and choosing that. Or c:\python27\python.exe if you have that.
To fix it without having to choose a file, you need to specify both where the Python interpreter is and where the scrapy file is, e.g.
python scrapy startproject myproject has to become something like
C:\Python27\python.exe C:\Python27\Scripts\scrapy startproject C:\Users\username\Documents\projects\myproject
(You will have to find out where Python.exe and scrapy are on your system. I am deliberately ignoring the Enthought path you show because I don't know anything about how it installs, and what folders it uses).
Edit: I suggest not changing the PATH because it might unintentionally break other things, and instead creating a wrapper for the scrapy launcher:
Rename Scripts\scrapy to Scripts\scrapy-helper
Create a file named Scripts\scrapy.bat with the content
C:\Python27\python.exe c:\Python27\Scripts\scrapy-helper %*
With the correct paths for your system. When you type scrapy at the command prompt, Windows/PowerShell will find it, run it as a batch file, call the right Python to run the right scrapy script, and pass any parameters you used through to Python.