Heat olive oil in a large skillet over medium heat.
Add the sliced onions and sprinkle with salt.
Cook the onions, stirring occasionally, for about 30-40 minutes until golden brown.
Season the caramelized onions with black pepper and stir well.
Meanwhile, bring a large pot of salted water to a boil and cook spaghetti according to package instructions.
Reserve a cup of pasta water, then drain the spaghetti.
Add the drained spaghetti to the skillet with caramelized onions.
Drizzle with chilli oil and toss everything together, adding reserved pasta water as needed.
Serve immediately, topped with optional grated Parmesan cheese.