When executing scripts or database operations that contain complex logic, environment variables, or special characters (such as single/double quotes, parentheses, %, $, etc.) in Node.js or Python, you MUST strictly adhere to the following rules:
node -e "..." or python -c "..." to execute complex logic.
% as ForEach-Object).
When you need to run one-off scripts (e.g., updating database schemas, migrating data, testing APIs), you must follow this workflow:
temp_update_db.js or temp_task.ts) in an appropriate directory (like scripts/ or the current working directory).
```javascript
import 'dotenv/config'; // For ESM
// OR
require('dotenv').config(); // For CJS
```
node temp_update_db.js or npx tsx temp_task.ts.
> NOTE: All temporary scripts must be prefixed with temp_. Ensure temp_* is added to .gitignore to prevent accidental commits.
If the terminal hangs, freezes, or displays an unexpected prompt (like waiting for user input) during execution, you must immediately stop the current operation. Assume the script triggered special escaping rules in the terminal environment, and retry using the standalone file execution method described above.
共 1 个版本