Initialize a new Node.js project: This will create a package.json file in your project directory.
cd my-node-project
npm init -y
Install dependencies: Use npm to install any libraries you need. For example, if you need Express.js, you would run:
Create your main file: Typically, this is index.js or app.js. Here’s a simple Express server
const app = express();
app.get(‘/‘, (req, res) => {
res.send(‘Hello World!‘);
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
Run your application: You can start your Node.js application with the following command:
Remember to replace express with any other dependencies you might need for your project. Also, you can add scripts to your package.json to streamline the start-up process, like so:
“start”: “node index.js”
}
Now, you can start your server with npm start. This is a basic setup, and your actual implementation might vary based on the project requirements.