npm Commands for Next.js/React.js Projects
1. Initialize a New Project
Use the following command to initialize a new project and create a package.json
file:
npm init
2. Install Project Dependencies
Install all project dependencies listed in the package.json
file:
npm install
3. Add a Dependency
Add a new dependency to your project:
npm install <package-name>
Example: Adding React as a dependency:
npm install react
4. Remove a Dependency
Remove a dependency from your project:
npm uninstall <package-name>
Example: Removing React as a dependency:
npm uninstall react
5. Update Dependencies
Update project dependencies to their latest compatible versions:
npm update
To update a specific package, use:
npm update <package-name>
6. Start the Development Server
Start the development server for your Next.js or React.js application:
npm start
7. Build for Production
Build your project for production:
npm run build
8. Run Tests
Run your project's test suite:
npm test
9. Run Custom Scripts
Execute a custom script defined in the package.json
file:
npm run <script-name>
Example: Running a script named lint
:
npm run lint
10. Clean Project
Remove the node_modules
directory to start fresh:
npm run clean
These commands will help you manage dependencies, start the development server, build for production, run tests, and execute custom scripts in your Next.js or React.js project. Remember to run these commands in your project's root directory using the terminal or command prompt.
Feel free to refer to the npm documentation for more information about each command. Happy coding!