DEV Community

Olatunji Ayodele Abidemi
Olatunji Ayodele Abidemi

Posted on

To create a new Node.js project and work with dependencies, you'll need to follow these steps

Initialize a new Node.js project: This will create a package.json file in your project directory.

mkdir my-node-project
cd my-node-project
npm init -y
Enter fullscreen mode Exit fullscreen mode

Install dependencies: Use npm to install any libraries you need. For example, if you need Express.js, you would run:

npm install express
Enter fullscreen mode Exit fullscreen mode

Create your main file: Typically, this is index.js or app.js. Here's a simple Express server

const express = require('express');
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}`);
});
Enter fullscreen mode Exit fullscreen mode

Run your application: You can start your Node.js application with the following command:

node index.js
Enter fullscreen mode Exit fullscreen mode

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:

"scripts": {
  "start": "node index.js"
}
Enter fullscreen mode Exit fullscreen mode

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.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more