I imported MVC template by running dotnet new mvc -lang C#. I got default template here but I noticed it's missing package.json file.
How can I add package.json in VSCode editor to this template to add other required references ?.
You can use npm init command from node package manager.
Open Nodejs command prompt.
Navigate to project directory.
type npm init command.
Specify basic details like name, version, description, entry point etc.
This will create basic of package.json. Then, you can use npm install <package> --save to install new npm packages in your project.
Other option is, you can create package.json manually.
Related
Each time when I start a new project I download many dependencies and configure some settings in VS Code again and again. For example I run these commands like npm install --save-dev webpack and npm install eslint --save-dev and copy some config files like .eslintrc.
Is there any way to avoid this?
I use npm and VS code.
the possible way is to delete the new node module folder and package.json from new installed project, and copy it from the old project.
there is no legal way to perform a new project without the installation of required packages through npm.
I'm new to nodejs and npm, just a question on dependencies and devDependencies
When I create a new react or Angular project, then I added a new required package by
npm install xxx --save
so the command above add the new package entry to "dependencies" in package.json file.
then I run npm start. The project is working OK and it is using the package I just installed.
But when I run npm start, I'm still in development environment, isn't it? and if the entry is not added to devDependencies, how can the application still run in development? I'm confused
The difference between these two, is that devDependencies are modules which are only required during development, while dependencies are modules which are also required at runtime. So while development we use both of them. For more details check here.
I have a react boilerplate that configures a nodejs server for background api calls and a create-react-app for the frontend.
I wanted to create a npm package that would prepare the whole environment when installing.
Eg.: npm i myPackage
This would create all the files and folders based on the structure I have defined, just like cloning the repository...
How could achieve that?
I just need some directions on how to start this, I published an npm package based on my repository and it only downloaded two files but not the whole structure.
Try adding a postinstall script like
"scripts": {
"postinstall": "./executable-script or cp dir/* $INIT_CWD/"
}
into the package.json file. It will run right after the package is installed.
For more documentation read https://docs.npmjs.com/misc/scripts and https://docs.npmjs.com/cli/run-script.
I never used it before, but it would likely solve it for you.
I have 2 projects(packages) in npm, I want to inject package_A as dependency to package_B. In package_A root folder, I run npm install -g, then npm install it to C:\Users\Myuser\AppData\Roaming\npm\node_moduls\package_A folder. Now in packages.json in package_B I add "package_A": "1.0.0" in dependencies. When in package_B root file I run npm install, its failed package_A#1.0.0 not found.
How can I identified npm to its my own local package?
Notes:
We are a team, then I don't want to address package_A explicitly.
We are using nexus repository manager.
I don't want to publish my projects to http://registry.npmjs.org/.
I'm not 100% clear what you have tried. If you are going to use a custom module for another application you are developing, installing globally won't do the trick. You have to publish that module in npm.
Check this link for more info on publishing in npm
If you have completed the steps correctly, and still no good happens, please check your naming of the module in package.json file.
Instead of typing in the name and version number in package.json file and then npm install, try directly installing in the terminal with --save so that it will automatically be added to package.json file with correct spelling.
Is there a way using npm to treat a file in the project as a node-module without linking it and it having it's own package.json?
Ideally I could just have a sub-module definition within my main app package.json and be able to install things to a specific module that way.
Here's an example
/app
/index.js
/file.js
/action.js
What I'd like
npm set-as-module ./action.js "action"
Then within any file in my project I can call
var action = require("action")
Then when I want to install specific dependancies for action I could do this
npm install underscore --save --sub=action
This this kind of feature exist within NPM? Anything close to it?
This would offer the following perks
Easy to branch out or publish into full module
ability to require with module string instead of path
I created something to do this
https://github.com/reggi/npm-link-file
npm install npm-link-file -g
npm-link-file ./action.js "action"
It does not handle linked dependancies.