65 lines
1.5 KiB
Markdown
65 lines
1.5 KiB
Markdown
# Node.js & JavaScript Skill
|
|
|
|
## Installed Versions
|
|
- Node.js 20.x
|
|
- npm 10.x
|
|
- Claude Code CLI
|
|
|
|
## Common Commands
|
|
|
|
### Project Initialization
|
|
```bash
|
|
npm init -y # Initialize package.json
|
|
npm install express # Install dependency
|
|
npm install -D nodemon # Install dev dependency
|
|
npm install --save-exact # Install exact version
|
|
```
|
|
|
|
### Development
|
|
```bash
|
|
npm start # Start app
|
|
npm run dev # Start with hot reload
|
|
npm test # Run tests
|
|
npm run build # Build for production
|
|
npm outdated # Check for updates
|
|
npm update # Update dependencies
|
|
```
|
|
|
|
### Docker for Node
|
|
```bash
|
|
# Basic Dockerfile
|
|
FROM node:20-alpine
|
|
WORKDIR /app
|
|
COPY package*.json ./
|
|
RUN npm ci --only=production
|
|
COPY . .
|
|
EXPOSE 3000
|
|
CMD ["npm", "start"]
|
|
```
|
|
|
|
## Project Templates
|
|
|
|
### Express API
|
|
```javascript
|
|
const express = require('express');
|
|
const app = express();
|
|
const port = 3000;
|
|
|
|
app.use(express.json());
|
|
app.get('/', (req, res) => res.send('Hello'));
|
|
app.listen(port, () => console.log(`Server on ${port}`));
|
|
```
|
|
|
|
### Fast Setup
|
|
```bash
|
|
npx create-next-app myapp # Next.js
|
|
npx create-react-app myapp # React
|
|
npx create-vue-app myapp # Vue
|
|
```
|
|
|
|
## Best Practices
|
|
- Use `npm ci` instead of `npm install` in CI/CD
|
|
- Use `package-lock.json` for reproducible builds
|
|
- Define scripts in package.json for common tasks
|
|
- Use environment variables with `dotenv`
|